|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-07-09 03:53 UTC] lucas at threeamdesign dot com
Description: ------------ --- From manual page: http://www.php.net/function.list --- The main description for the construct should specify that it only operates on numeric indices of an array (i.e. string keys are ignored) and expects them to be consecutive and starting at 0. It should also state that the order in which the indices were defined is irrelevant. Test script: --------------- This behaviour could be explained clearly, like so: <?php $foo = array(2 => 'a', 'foo' => 'b', 0 => 'c'); $foo[1] = 'd'; list($x, $y, $z) = $foo; var_dump($foo, $x, $y, $z); ?> produces the following result: array(4) { [2]=> string(1) "a" ["foo"]=> string(1) "b" [0]=> string(1) "c" [1]=> string(1) "d" } string(1) "c" string(1) "d" string(1) "a" PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 06 23:00:02 2026 UTC |
What's the benefit of breaking the current functionality? I don't think it behaves in an implementation-specific way now, so it shouldn't in the future. It'd be better to show the example with array_values() as well: <?php $foo = array(2 => 'a', 'foo' => 'b', 0 => 'c'); $foo[1] = 'd'; var_dump($foo); echo PHP_EOL; list($x, $y, $z) = $foo; var_dump($x, $y, $z); echo PHP_EOL; list($x, $y, $z) = array_values($foo); var_dump($x, $y, $z); ?> produces: array(4) { [2]=> string(1) "a" ["foo"]=> string(1) "b" [0]=> string(1) "c" [1]=> string(1) "d" } string(1) "c" string(1) "d" string(1) "a" string(1) "a" string(1) "b" string(1) "c"