|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7762 array_multisort() doesn't always correctly reassign references between values
Submitted: 2000-11-11 14:38 UTC Modified: 2002-02-26 21:40 UTC
From: noog at libero dot it Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.0.2 OS: Windows 98 SE (4.10.2222)
Private report: No CVE-ID: None
 [2000-11-11 14:38 UTC] noog at libero dot it
#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)

    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'];



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-26 21:40 UTC]
The version of PHP that this bug was reported in is too old. Please
try to reproduce this bug in the latest version of PHP (available

If you are still able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Jun 26 02:05:44 2022 UTC