For loop question?

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....


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 4 Days Ago
Iván Sánchez Ortega
 
Posts: n/a
Default Re: For loop question?

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.
Reply With Quote
  #12 (permalink)  
Old 4 Days Ago
Rik Wasmus
 
Posts: n/a
Default Re: For loop question?

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
Reply With Quote
  #13 (permalink)  
Old 3 Days Ago
SM
 
Posts: n/a
Default Re: For loop question?

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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:01 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0