Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Nov 14, 2010 Nov 14, 2010

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

TOPICS
Server side applications
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Nov 16, 2010 Nov 16, 2010

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

Translate
Participant ,
Nov 16, 2010 Nov 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 16, 2010 Nov 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Nov 16, 2010 Nov 16, 2010
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines