Jump to content

quick question on list() and each()


arianhojat

Recommended Posts

<?php
$foo = array("Robert" => "Bob", "Seppo" => "Sepi");
$bar = each($foo);
print_r($bar);
echo "\n\n";

//So this shows that each() returns a 4 element array so if you supposedly pass it to list() with 4 arguements within list(), how come only the index keys from the array created by each() only come over?

reset($foo); //start array pointer back to beginning since called each() be4

while ( list($key, $val, $assosKey, $assocVal) = each($foo) )
echo "$key => $val (or $assosKey => $assocVal)\n";

//only prints out index values, but not the associative key/value pairs returned by the array.
//Is it cause they one points to same place in memory really, so one is really a reference to the other?
//or the list function only can take the index keys?


?> 


Link to comment
https://forums.phpfreaks.com/topic/36392-quick-question-on-list-and-each/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.