For Programmers: Free Programming Magazines  


Home > Archive > PHP Documentation > March 2004 > #27788 [Opn]: array_multisort doesn't mantain index associations with numeric arrays









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author #27788 [Opn]: array_multisort doesn't mantain index associations with numeric arrays
derick@php.net

2004-03-31, 5:34 am

ID: 27788
Updated by: derick@php.net
Reported By: mail at spybreak dot de
Status: Open
-Bug Type: Feature/Change Request
+Bug Type: Documentation problem
Operating System: Win2K
PHP Version: 4.3.4
Assigned To: andrei
New Comment:

Making this a documentation problem, as it is the correct behavior.


Previous Comments:
------------------------------------------------------------------------

[2004-03-30 19:30:58] 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'


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=27788&edit=1
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com