Req #55158 [PATCH]: Add SORT_NATURAL type to array_multisort

From: Date: Tue, 12 Jul 2011 15:58:09 +0000
Subject: Req #55158 [PATCH]: Add SORT_NATURAL type to array_multisort
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-161828@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55158&edit=1

 ID:                 55158
 Patch added by:     arpad@php.net
 Reported by:        joe dot lencioni+php at gmail dot com
 Summary:            Add SORT_NATURAL type to array_multisort
 Status:             Open
 Type:               Feature/Change Request
 Package:            Arrays related
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2011-07-07 15:00:19] 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)



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



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=55158&edit=1


Thread (8 messages)

« previous php.bugs (#161828) next »