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

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

Explorer ,
Nov 14, 2010 Nov 14, 2010

Copy link to clipboard

Copied

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

Views

1.4K
Translate

Report

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

Votes

Translate
Participant ,
Nov 16, 2010 Nov 16, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Report

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

Copy link to clipboard

Copied

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

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

{ echo "$index - $value";}

Thanks for your answer anyway.

Votes

Translate

Report

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

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Report

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