Last active
August 29, 2015 13:56
-
-
Save chrisguitarguy/9064527 to your computer and use it in GitHub Desktop.
PHP list weirdness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$one = array('two', 'one'); | |
list($two, $one) = $one; | |
var_dump($one, $two); | |
/* Output | |
string(3) "one" | |
string(1) "o" | |
*/ | |
/* | |
Reason: http://us1.php.net/list#refsect1-function.list-notes | |
list() assigns the values starting with the right-most parameter. | |
If you are using plain variables, you don't have to worry about this. | |
Modification of the array during list() execution (e.g. using | |
list($a, $b) = $b) results in undefined behavior. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment