Skip to main content
Participating Frequently
November 14, 2010
해결됨

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

  • November 14, 2010
  • 1 답변
  • 1468 조회

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

이 주제는 답변이 닫혔습니다.
최고의 답변: w1n78

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

1 답변

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

Not_Relevant1작성자
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
w1n78답변
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