This is a discussion on For loop question? within the PHP Language forums, part of the PHP Programming Forums category; Rik Wasmus wrote: > The correct way to do this is: > > $cats = array( > 1 => array('moonlight....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Rik Wasmus wrote:
> The correct way to do this is: > > $cats = array( > 1 => array('moonlight.jpg' .......), > 2 => array(....), > 3 => array(....)); An alternate way to do the same is: $cats[1] = array('moonlight.jpg' .......); $cats[2] = array('foobar' .......); $cats[3] = array(...); > And then just use: > > foreach($cats[$_GET['cat'] as $img) echo $img; You're missing a "]" here, Rik! foreach($cats[ $_GET['cat'] ] as $img) echo $img; -- ---------------------------------- Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org- Un ordenador no es un televisor ni un microondas, es una herramienta compleja. |
|
|||
|
On Thu, 08 May 2008 23:14:44 +0200, Iván Sánchez Ortega
<ivansanchez-alg@rroba-escomposlinux.-.punto.-.org> wrote: > Rik Wasmus wrote: > >> The correct way to do this is: >> >> $cats = array( >> 1 => array('moonlight.jpg' .......), >> 2 => array(....), >> 3 => array(....)); > > An alternate way to do the same is: > > $cats[1] = array('moonlight.jpg' .......); > $cats[2] = array('foobar' .......); > $cats[3] = array(...); > >> And then just use: >> >> foreach($cats[$_GET['cat'] as $img) echo $img; > > You're missing a "]" here, Rik! Oh no! Now all I say is suspect, and therefor should not be followed. Forget what I said, having $cat_1 & $cat_2 like variable names must be a great idea :). -- Rik Wasmus |
|
|||
|
On May 8, 5:21 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
> On Thu, 08 May 2008 23:14:44 +0200, Iván Sánchez Ortega > > > > <ivansanchez-...@rroba-escomposlinux.-.punto.-.org> wrote: > > Rik Wasmus wrote: > > >> The correct way to do this is: > > >> $cats = array( > >> 1 => array('moonlight.jpg' .......), > >> 2 => array(....), > >> 3 => array(....)); > > > An alternate way to do the same is: > > > $cats[1] = array('moonlight.jpg' .......); > > $cats[2] = array('foobar' .......); > > $cats[3] = array(...); > > >> And then just use: > > >> foreach($cats[$_GET['cat'] as $img) echo $img; > > > You're missing a "]" here, Rik! > > Oh no! Now all I say is suspect, and therefor should not be followed. > Forget what I said, having $cat_1 & $cat_2 like variable names must be a > great idea :). > -- > Rik Wasmus Thanks Rik. Try it and it work perfectly! And i didn't need to read the PHP Manual. I guess that's what a forum is for. Thanks again for beeing 'in the mood' Marco |
![]() |
| Thread Tools | |
| Display Modes | |
|
|