note 112920 deleted from function.usort by cmb
| From: | cmb@php.net | Date: | Sun, 13 Oct 2019 08:13:20 +0000 |
| Subject: | note 112920 deleted from function.usort by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212628@lists.php.net to get a copy of this message | ||
Note Submitter: me at perochak dot com
----
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
)