note 16306 modified in function.list by irc-html

From: Date: Sat, 19 Jan 2002 22:05:52 +0000
Subject: note 16306 modified in function.list by irc-html
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-25507@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. --was-- 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

« previous php.notes (#25507) next »