Page 1 of 1

Simple Array Question

Posted: Sat Apr 17, 2010 8:17 pm
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?

Re: Simple Array Question

Posted: Sat Apr 17, 2010 9:15 pm
by Benjamin
You are setting the value of $George five times.

Re: Simple Array Question

Posted: Sat Apr 17, 2010 9:22 pm
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.

Re: Simple Array Question

Posted: Sat Apr 17, 2010 9:30 pm
by Benjamin
The value of George will be the value of $List[$i]. Can you post the actual code?

Re: Simple Array Question

Posted: Sat Apr 17, 2010 9:42 pm
by JackD
Found the problem..... it was some missing parentheses around the $George.

Thanks