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
ya that's how i use it. i had to look up what each() does haha coz i don't use it
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
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.
Copy link to clipboard
Copied
ya that's how i use it. i had to look up what each() does haha coz i don't use it