Ask a Question related to PHP Development, Design and Development.
-
sniper@php.net #1
#24897 [Opn->Asn]: array_multisort() will reindex the array but not if array length is 1
ID: 24897
Updated by: [email]sniper@php.net[/email]
Reported By: chro at sokrates dot uio dot no
-Status: Open
+Status: Assigned
Bug Type: Arrays related
Operating System: RH 9.0
-PHP Version: 5.0.0b1 (beta1)
+PHP Version: 5.0.0b2-dev, 4.3.3RC3-dev
-Assigned To:
+Assigned To: andrei
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2003-07-31 21:04:59] 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
[url]http://bugs.php.net/bug.php?id=12572[/url]
(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
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=24897&edit=1[/url]
sniper@php.net Guest
-
Array length problem
I seem to have a problem with the "array length". I can't seem to find any info as to what this refers to. Can anyone tell what this means. I am... -
Reg. length of anonymous array
Hi, How can I rearrange an array in a specific order based on the order of a hash? Something like this: my @a = qw(Mary John Dan); print join... -
#19617 [Ver->Bgs]: Array_multisort don't work on GLOBAL array
ID: 19617 Updated by: sniper@php.net Reported By: jpapin at free dot fr -Status: Verified +Status: ... -
#24897 [Com]: array_multisort() will reindex the array but not if array length is 1
ID: 24897 Comment by: franklin_se at hotmail dot com Reported By: chro at sokrates dot uio dot no Status: ... -
#21788 [Sus->WFx]: array_multisort() changes array keys unexpectedly given numeric strings as keys
ID: 21788 Updated by: sniper@php.net Reported By: jon at inet-specialists dot com -Status: Suspended +Status: ...



Reply With Quote

