Skip to main content
Participating Frequently
November 14, 2010
Answered

while (list ($index; $value) = each ($array)) { echo "Wtf?!"; }

  • November 14, 2010
  • 1 reply
  • 1467 views

Hello fellows!

I'm new to PHP and now I'm stuck at list(); and each(); functions.

Can anyone explain me the meaning of:

list ($index; $value) = each ($array) ?

I understand that the meaning of variables in this code:

$array[index]="value";

But what is the meaning of the equation in the brackets of while cycle?

Thank you people!

DissidentPJ

This topic has been closed for replies.
Correct answer w1n78

ya that's how i use it. i had to look up what each() does haha coz i don't use it

1 reply

w1n78
Participating Frequently
November 16, 2010

list assigns variables the value of an array (http://us3.php.net/list)

example

$array = array('blue', 'red', 'yellow');

list ($var1, $var2, $var3) = $array;

echo $var1;     // blue

echo $var2;     // red

echo $var3;     // yellow

each() will return both key and value of an array

so if you apply each() to the above example you would get something like (key => value) (http://us3.php.net/manual/en/function.each.php)

[0] => blue

[1] => red

[2] => yellow

Participating Frequently
November 16, 2010

I've found out that most PHP programmers now use:

foreach ($array as $index=>$value)

{ echo "$index - $value";}

Thanks for your answer anyway.

w1n78
w1n78Correct answer
Participating Frequently
November 17, 2010

ya that's how i use it. i had to look up what each() does haha coz i don't use it