php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #28833 make array_multisort more easy to use
Submitted: 2004-06-18 18:11 UTC Modified: 2011-01-02 02:12 UTC
From: xuefer at 21cn dot com Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 4.3.7 OS: all
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-06-18 18:11 UTC] xuefer at 21cn dot com
Description:
------------
$ar = array(array("10", 100, 100, "a"), array(1, 3, "2", 1)); 

we now must do:
array_multisort($ar[0], SORT_ASC, SORT_STRING, 
               $ar[1], SORT_NUMERIC, SORT_DESC); 

1.
========

how about:
array_multisort($ar, "0", SORT_ASC, SORT_STRING, 
               "1", SORT_NUMERIC, SORT_DESC); 

but "int" type of key may mixed with sort flags :(

nicer example:
$ar = array('abc' => array("10", 100, 100, "a"), 'def' => array(1, 3, "2", 1)); 
array_multisort($ar, "abc", SORT_ASC, SORT_STRING, 
               "def", SORT_NUMERIC, SORT_DESC); 

this is VERY useful when you have so many arrays in $ar, but only want to sort BY some of it

2.
========
because "SHOW PROCESSLIST" cannot do a "ORDER BY"
we need:
/*
$rows = array();
while ($row = mysqli_fetch_assoc()) {
  $rows[] = $row;
}
*/
$rows = array(
  array('a' => "10", 'b' => 100, 'c' => 100, 'd' => "a"),
  array('a' => 1, 'a' => 3, 'a' => "2", 'd' => 1)
); 
array_multisort_rows($row, "a", SORT_ASC, SORT_STRING, 
               "b", SORT_NUMERIC, SORT_DESC); 



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-02 02:12 UTC] jani@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues
 [2011-01-02 02:12 UTC] jani@php.net
It's fine as it is.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 00:01:27 2024 UTC