php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: noog at libero dot it
New email:
PHP Version: OS:

 

 [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)
);

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

*/

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-02-26 21:40 UTC] yohgaki@php.net
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
from http://www.php.net/downloads.php

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-2019 The PHP Group
All rights reserved.
Last updated: Fri Jun 21 00:01:26 2019 UTC