note 92375 rejected from function.list by danbrown

From: Date: Tue, 21 Jul 2009 22:39:37 +0000
Subject: note 92375 rejected from function.list by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158565@lists.php.net to get a copy of this message
Note Submitter: Ray dot Paseur at Gmail dot com ---- Example 4, above, is not exactly right. This code shows the difference experienced with PHP 5.2.6. Also, the warning about the assignment order may be confusing. If fewer arguments are contained in list() than are present in the array, the assignment to list elements is made "left-to-right" across the array, up to the number of arguments in list(). If more arguments are in list() than in the array, a Notice is generated and the excess arguments are assigned NULL. <?php // IF YOU OMIT THIS STATEMENT, $a IS NOT MADE INTO AN ARRAY // $a = array(); // $a IS NOT AN ARRAY $info = array('coffee', 'brown', 'caffeine'); list($a[0], $a[1], $a[2]) = $info; var_dump($a); // PRINTS string(3) "cbc" // IF YOU INCLUDE THIS STATEMENT, $a IS MADE INTO AN ARRAY $a = array(); $info = array('coffee', 'brown', 'caffeine'); list($a[0], $a[1], $a[2]) = $info; var_dump($a); // PRINTS array(3) { [2]=> string(8) "caffeine" [1]=> string(5) "brown" [0]=> string(6) "coffee" } // IF YOU USE FEWER ARGUMENTS FOR list() THE ASSIGNMENT IS LEFT-TO-RIGHT $a = array(); $info = array('coffee', 'brown', 'caffeine'); list($a[0], $a[1]) = $info; var_dump($a); // PRINTS array(2) { [1]=> string(5) "brown" [0]=> string(6) "coffee" }

« previous php.notes (#158565) next »