Simple Array Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JackD
Forum Commoner
Posts: 62
Joined: Sat Dec 12, 2009 6:25 pm

Simple Array Question

Post by JackD »

In the following:

Code: Select all

for ($i=0; $i<5; $i++)
       { $George=$List[$i];
         echo $List[$i];     // this works okay
         echo $George;     // this does not work
       }
the value echoed is what I wanted while $George is set to null. What am I doing wrong?
Last edited by JackD on Sat Apr 17, 2010 9:23 pm, edited 1 time in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Simple Array Question

Post by Benjamin »

You are setting the value of $George five times.
JackD
Forum Commoner
Posts: 62
Joined: Sat Dec 12, 2009 6:25 pm

Re: Simple Array Question

Post by JackD »

The code snippet is abbreviated. We actually use the value of $George as we iterate through the array, or rather we would if $George were to be set as we expected.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Simple Array Question

Post by Benjamin »

The value of George will be the value of $List[$i]. Can you post the actual code?
JackD
Forum Commoner
Posts: 62
Joined: Sat Dec 12, 2009 6:25 pm

Re: Simple Array Question

Post by JackD »

Found the problem..... it was some missing parentheses around the $George.

Thanks
Post Reply