note 112920 added to function.usort
| From: | me at perochak dot com | Date: | Wed, 07 Aug 2013 08:37:59 +0000 |
| Subject: | note 112920 added to function.usort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-195896@lists.php.net to get a copy of this message | ||
If you want to sort the time based array, then this will be helpfull.
function timesort($array){
usort($array, function($a, $b)
{
$a=strtotime($a);
$b=strtotime($b);
if ($a == $b)
{
return 0;
}
else if ($a < $b)
{
return -1;
}
else {
return 1;
}
});
}
Input:
$time_array=Array
(
[1] => 10:00AM
[2] => 09:00AM
[3] => 02:00PM
[4] => 11:00AM
)
Output:
print_r(timesort($time_array));
Array
(
[0] => 09:00AM
[1] => 10:00AM
[2] => 11:00AM
[3] => 02:00PM
)
----
Server IP: 69.147.83.199
Probable Submitter: 182.185.134.36
----
Manual Page -- http://php.net/manual/en/function.usort.php
Edit -- https://master.php.net/note/edit/112920
Del: integrated -- https://master.php.net/note/delete/112920/integrated
Del: useless -- https://master.php.net/note/delete/112920/useless
Del: bad code -- https://master.php.net/note/delete/112920/bad+code
Del: spam -- https://master.php.net/note/delete/112920/spam
Del: non-english -- https://master.php.net/note/delete/112920/non-english
Del: in docs -- https://master.php.net/note/delete/112920/in+docs
Del: other reasons-- https://master.php.net/note/delete/112920
Reject -- https://master.php.net/note/reject/112920
Search -- https://master.php.net/manage/user-notes.php