[php] random array, slechts gedeelte laten zien

Pagina: 1
Acties:
  • 147 views

Acties:
  • 0 Henk 'm!

  • likkepot
  • Registratie: April 2002
  • Laatst online: 06-12-2024

likkepot

Ghehe ghe heehe!

Topicstarter
Ik ben een pagina aan het maken waarin een aantal DIV layers at random onder elkaar worden weergeven.
Er is een array waarin alle layers staan. Deze worden geshuffeld.
Maar van de 5 layers, wil ik er maar 3 echo'en. Het probleem is dat hij toch de hele array laat zien. Wat gaat er mis?
Stukje code:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
$content = array(
    '<div style=" height: 10px; width:100px; background-color:#0FC">START</div><br>',
    '<div style=" height: 10px; width:100px; background-color:#0FC">ABOUT</div><br>',
    '<div style=" height: 10px; width:100px; background-color:#0FC">WORK</div><br>',
    '<div style=" height: 10px; width:100px; background-color:#0FC">CONTACT</div><br>',
    '<div style=" height: 10px; width:100px; background-color:#0FC">BLOG</div><br>'
    
);

shuffle($content);

foreach ($content as $value)
$count = count($value); //telt het aantal div layers
else
$count = 3;
for ($i = 0; $i < $count; $i ++)
{
    $explode = explode('|', $value);
    echo '' . $explode[0] . '';
}
?>

nikszolekkeralss.exe


Acties:
  • 0 Henk 'm!

  • HuHu
  • Registratie: Maart 2005
  • Niet online
Snap je zelf wel wat je code doet?

Acties:
  • 0 Henk 'm!

  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 21-09 21:47

Creepy

Tactical Espionage Splatterer

No offence maar ga zelf eens debuggen en laat je code eens fatsoenlijk inspringen.
PHP:
1
2
3
4
foreach ($content as $value)
$count = count($value); //telt het aantal div layers
else
$count = 3;

Word count nu 3 of niet? Met een paar printf weet je welke toekening aan $count wordt uitgevoerd. Soieso is een else i.c.m. met een foreach op deze manier vreemd.

Ga zelf eens echt na wat je code doet en hoe het werkt. Het is hier geen plek om je code te dumpen en ons de oplossing te laten zoeken. Debuggen zul je in eerste instantie zelf moeten doen.

[ Voor 30% gewijzigd door Creepy op 26-03-2009 16:30 ]

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney


Dit topic is gesloten.