note 68539 deleted from function.array-multisort by bjori
| From: | bjori@php.net | Date: | Wed, 02 Aug 2006 12:52:51 +0000 |
| Subject: | note 68539 deleted from function.array-multisort by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-115449@lists.php.net to get a copy of this message | ||
Note Submitter: kab design at kab design dot com dot au
Reason: bad code
----
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.