PHP 4.0 Bug #7762: array_multisort() doesn't always correctly reassign references between values
| From: | noog at libero dot it | Date: | Sat, 11 Nov 2000 19:38:36 +0000 |
| Subject: | PHP 4.0 Bug #7762: array_multisort() doesn't always correctly reassign references between values | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-37768@lists.php.net to get a copy of this message | ||
From: noog@libero.it
Operating system: Windows 98 SE (4.10.2222)
PHP version: 4.0.2
PHP Bug Type: Arrays related
Bug description: array_multisort() doesn't always correctly reassign references between values
#This is pretty strange.
#I didn't even know how to describe this
$db = array(
-1 => array('field0', 'field1', 'field2'),
'field0' => array(9, 2, 4, 8),
'field1' => array(333, 111, 333, 1),
'field2' => array(101010, 1, 22, 1111)
);
for($i=0;$i<4;$i++){
foreach($db[-1] as $fieldname){
$db[$i][$fieldname] = &$db[$fieldname][$i];
}
}
#will print the same value (2)
echo $db['field0'][1];
echo $db[1]['field0'];
#we change $db['field0'][1]
$db['field0'][1] = 2000;
#will still print the same value (2000)
echo $db['field0'][1];
echo $db[1]['field0'];
array_multisort($db['field0'], $db['field1']);
#we change $db['field0'][1]
$db['field0'][1] = 600;
#will print 600
echo $db['field0'][1];
#will print 2000
echo $db[1]['field0'];
#the two values have been 'unlinked'?
/* PLEASE NOTE this will work:
array_multisort($db[0], $db[1]);
#we change $db['field0'][1]
$db['field0'][1] = 600;
#will print the same value (600)
echo $db['field0'][1];
echo $db[1]['field0'];
*/
--
Edit Bug report at: http://bugs.php.net/?id=7762&edit=1