php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55158 Add SORT_NATURAL type to array_multisort
Submitted: 2011-07-07 15:00 UTC Modified: 2012-03-09 13:50 UTC
From: joe dot lencioni+php at gmail dot com Assigned: arpad
Status: Closed Package: Arrays related
PHP Version: 5.3.6 OS:
Private report: No CVE-ID:
 [2011-07-07 15:00 UTC] joe dot lencioni+php at gmail dot com
Description:
------------
Arrays often need to be sorted using a "natural order" algorithm. There are 
currently functions in PHP for sorting single arrays this way (natsort, 
natcasesort), but nothing exists for a multisort.

It would be great to see a SORT_NATURAL option in the array_multisort function.

Test script:
---------------
$a	= array(
	'Second',
	'First',
	'Twentieth',
	'Tenth',
	'Third',
);

$b	= array(
	'2 a',
	'1 b',
	'20 c',
	'10 d',
	'3 e',
);

array_multisort($b, SORT_NATURAL, $a);

var_dump($a, $b);

Expected result:
----------------
array
  0 => string 'First' (length=5)
  1 => string 'Second' (length=6)
  2 => string 'Third' (length=5)
  3 => string 'Tenth' (length=5)
  4 => string 'Twentieth' (length=9)
array
  0 => string '1 b' (length=3)
  1 => string '2 a' (length=3)
  2 => string '3 e' (length=3)
  3 => string '10 d' (length=4)
  4 => string '20 c' (length=4)


Patches

php-trunk-array_multisort-natural-case-new-tests (last revision 2011-08-04 16:01 UTC) by arpad@php.net)
php-trunk-array_multisort-natural-case-old-tests (last revision 2011-08-04 16:01 UTC) by arpad@php.net)
php-trunk-array_multisort-natural-case (last revision 2011-08-04 16:00 UTC) by arpad@php.net)
trunk-multisort-natural (last revision 2011-07-12 15:58 UTC) by arpad@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-12 11:58 UTC] arpad@php.net
The following patch has been added/updated:

Patch Name: trunk-multisort-natural
Revision:   1310486289
URL:        https://bugs.php.net/patch-display.php?bug=55158&patch=trunk-multisort-natural&revision=1310486289
 [2011-07-12 12:00 UTC] arpad@php.net
The patch I just added implements SORT_NATURAL and also adds SORT_CASE which can be combined with SORT_STRING and SORT_NATURAL to make the sorting case-insensitive.
 [2011-08-04 16:00 UTC] arpad@php.net
The following patch has been added/updated:

Patch Name: php-trunk-array_multisort-natural-case
Revision:   1312473647
URL:        https://bugs.php.net/patch-display.php?bug=55158&patch=php-trunk-array_multisort-natural-case&revision=1312473647
 [2011-08-04 16:01 UTC] arpad@php.net
The following patch has been added/updated:

Patch Name: php-trunk-array_multisort-natural-case-old-tests
Revision:   1312473669
URL:        https://bugs.php.net/patch-display.php?bug=55158&patch=php-trunk-array_multisort-natural-case-old-tests&revision=1312473669
 [2011-08-04 16:01 UTC] arpad@php.net
The following patch has been added/updated:

Patch Name: php-trunk-array_multisort-natural-case-new-tests
Revision:   1312473685
URL:        https://bugs.php.net/patch-display.php?bug=55158&patch=php-trunk-array_multisort-natural-case-new-tests&revision=1312473685
 [2011-08-29 20:23 UTC] derick@php.net
Automatic comment from SVN on behalf of derick
Revision: http://svn.php.net/viewvc/?view=revision&revision=315737
Log: - Zend engine part for bug #55158: Add SORT_NATURAL type to array_multisort
  (patch by Arpad Ray).
 [2011-08-29 20:26 UTC] arpad@php.net
-Status: Open +Status: To be documented
 [2011-08-29 20:26 UTC] arpad@php.net
Added SORT_NATURAL and SORT_FLAG_CASE which affects sort, rsort, ksort, krsort, asort, arsort and array_multisort.
 [2012-03-09 13:47 UTC] arpad@php.net
Automatic comment from SVN on behalf of arpad
Revision: http://svn.php.net/viewvc/?view=revision&revision=324055
Log: Docs for #55158 (adding SORT_NATURAL and SORT_FLAG_CASE)
 [2012-03-09 13:50 UTC] arpad@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: arpad
 [2012-03-09 13:50 UTC] arpad@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php


 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 09:02:28 2014 UTC