note 16306 added to function.list
| From: | pgl at instinct dot org | Date: | Wed, 24 Oct 2001 12:40:19 +0000 |
| Subject: | note 16306 added to function.list | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-19371@lists.php.net to get a copy of this message | ||
If you use list() to assign to an array with the same name as the array being assigned from, the
array with overwrite the values in the source array. eg:
<?
$a = array('a', 'b');
list($a[0], $a['x']) = $a;
print_r($a);
?>
gives:
Array
(
[0] => a
[1] => b
[x] => b
)
if you try and use list to assign to an array, using an array which is the return value of the
target array, it doesn't work. eg:
<?
$a = 'a:b';
list($a['x'], $a['y']) = explode(':', $a);
print_r($a);
?>
gives:
a:b
this is true for any function that returns an array, including user defined arrays.
--
http://www.php.net/manual/en/function.list.php
http://master.php.net/manage/user-notes.php?action=edit+16306
http://master.php.net/manage/user-notes.php?action=delete+16306
http://master.php.net/manage/user-notes.php?action=reject+16306