note 68539 added to function.array-multisort
| From: | kabdesignatkabdesigndotcomdotau at osu1 dot php dot net | Date: | Tue, 01 Aug 2006 12:28:20 +0000 |
| Subject: | note 68539 added to function.array-multisort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115408@lists.php.net to get a copy of this message | ||
If you are looking for a date sorting function on multidimensional arrays this works for me.
<?
$new_array = array('0'=>array('dd'=>'11',
'mm'=>'12', 'yy'=>'2006'),
'1'=>array('dd'=>'08', 'mm'=>'02',
'yy'=>'2004'),
'2'=>array('dd'=>'20', 'mm'=>'08',
'yy'=>'2080'));
foreach($new_array as $res) {
$sortDay[] = $res['dd'];
}
array_multisort($sortDay, SORT_ASC, $new_array);
foreach($new_array as $res) {
$sortYearMonth[] = $res['yy'].$res['mm'];
}
array_multisort($sortYearMonth, SORT_ASC, $new_array);
print_r($new_array);
?>
Please note it does require that the day and month is a two digit number, I suggest using a strpad
if you need to, also numbers not enclosed in ' ' will not work.
----
Server IP: 83.138.144.80
Probable Submitter: 81.158.133.2
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.array-multisort.php
Edit -- https://master.php.net/note/edit/68539
Del: integrated -- https://master.php.net/note/delete/68539/integrated
Del: useless -- https://master.php.net/note/delete/68539/useless
Del: bad code -- https://master.php.net/note/delete/68539/bad+code
Del: spam -- https://master.php.net/note/delete/68539/spam
Del: non-english -- https://master.php.net/note/delete/68539/non-english
Del: in docs -- https://master.php.net/note/delete/68539/in+docs
Del: other reasons-- https://master.php.net/note/delete/68539
Reject -- https://master.php.net/note/reject/68539
Search -- https://master.php.net/manage/user-notes.php