php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24897 array_multisort() will reindex the array but not if array length is 1
Submitted: 2003-07-31 21:04 UTC Modified: 2003-08-09 15:50 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: chro at sokrates dot uio dot no Assigned: andrei (profile)
Status: Closed Package: Arrays related
PHP Version: 5.0.0b2-dev, 4.3.3RC3-dev OS: RH 9.0
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: chro at sokrates dot uio dot no
New email:
PHP Version: OS:

 

 [2003-07-31 21:04 UTC] chro at sokrates dot uio dot no
Description:
------------
array_multisort() will reindex the array but not if array length is 1
Produced and reproduced in php.4.3.x and up to 5.beta

Similar (but not the same) as
http://bugs.php.net/bug.php?id=12572
(different function, 12572 is sort() )

Reproduce code:
---------------
<?php 

// array_multisort() will reindex the array but not if array length is 1, is
this a bug? 

// array length 1 

$a = array(1=>1); 
array_multisort($a); 
var_dump($a); 

// output: array(1) { [1]=> int(1) } 
// first index 1, not reindexed! 

//---------------------- 

// array length 2 

$a = array(1=>1,2); 
array_multisort($a); 
var_dump($a); 

// output: array(2) { [0]=> int(1) [1]=> int(2) } 
// first index 0, reindexed! 

?>

Expected result:
----------------
Array should be reindexed to:
output: array(1) { [0]=> int(1) } 
on first attempt (where array length = 1)

Actual result:
--------------
output: array(1) { [1]=> int(1) } 

array is not reindexed

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-01 07:02 UTC] sniper@php.net
From sources:
        /* If all arrays are empty or have only one entry,
           we don't need to do anything. */

According to that, this is the expected behaviour.
This was for empty arrays first, but Andrei changed it
later with this commit:

array.c:r1.43 (PHP array_multisort) Fix the array_size test.

Assigning to Andrei who should decide whether the reindexing should be done for 1 element arrays or not.

 [2003-08-02 10:29 UTC] franklin_se at hotmail dot com
Yes, it might not a bug, rather a minor inconsistancy.
I must say I expected it to get reindexed as well.

franklin
 [2003-08-09 15:50 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


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