php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #27788 array_multisort doesn't mantain index associations with numeric arrays
Submitted: 2004-03-30 19:30 UTC Modified: 2004-03-31 03:03 UTC
From: mail at spybreak dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.4 OS: Win2K
Private report: No CVE-ID: None
 [2004-03-30 19:30 UTC] mail at spybreak dot de
Description:
------------
The manual says that array_multisort mantains key associations. This is only true if the keys are strings. If the keys are integers on the other hand, key association is not mantained. I don't think that this is a bug since it's so obvious. But I wish feedback on this to clear this issue up. Thanks alot!

Reproduce code:
---------------
<?
//names array. keys are user id's
$names[5]  = 'Peter';
$names[7]  = 'Jim';
$names[11] = 'Martin';
$names[33] = 'John';
$names[34] = 'Robert';

//age array. keys are user id's
$age[5]    = 15;
$age[7]    = 19;
$age[11]   = 54;
$age[33]   = 29;
$age[34]   = 17;

//sort names array by ages
array_multisort($age, $names);

var_dump($names);
?>

Expected result:
----------------
I expect this:

// _should_ return
//
// array
//   5  => 'Peter'
//   34 => 'Robert'
//   7  => 'Jim'
//   33 => 'John'
//   11 => 'Martin'

Actual result:
--------------
// returns the following for me
//
// array
//   0 => 'Peter'       
//   1 => 'Robert'
//   2 => 'Jim'   
//   3 => 'John'   
//   4 => 'Martin' 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-31 02:08 UTC] derick@php.net
Making this a documentation problem, as it is the correct behavior.
 [2004-03-31 03:03 UTC] irchtml@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 20:01:29 2024 UTC