3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function sortDurations($a, $b) { if (strcmp($a['start'], $b['start']) == 0) { return 0; } else if (strcmp($a['start'], $b['start']) < 0) { return -1; } else if (strcmp($a['start'], $b['start']) > 0) { return 1; } return 0; } $tab = array(); $tab [] = array('start'=>'10:00:00','finish'=>'10:30:00'); $tab [] = array('start'=>'11:00:00','finish'=>'11:00:00'); $tab [] = array('start'=>'12:00:00','finish'=>'12:30:00'); $tab [] = array('start'=>'08:00:00','finish'=>'08:30:00'); $tab [] = array('start'=>'09:00:00','finish'=>'09:30:00'); echo "avant tri <pre>"; print_r($tab); echo "</pre>"; uasort($tab, 'sortDurations' ); echo "apres tri <pre>"; var_dump($tab); echo "</pre>"; ?>
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
avant tri <pre>Array ( [0] => Array ( [start] => 10:00:00 [finish] => 10:30:00 ) [1] => Array ( [start] => 11:00:00 [finish] => 11:00:00 ) [2] => Array ( [start] => 12:00:00 [finish] => 12:30:00 ) [3] => Array ( [start] => 08:00:00 [finish] => 08:30:00 ) [4] => Array ( [start] => 09:00:00 [finish] => 09:30:00 ) ) </pre>apres tri <pre>array(5) { [3]=> array(2) { ["start"]=> string(8) "08:00:00" ["finish"]=> string(8) "08:30:00" } [4]=> array(2) { ["start"]=> string(8) "09:00:00" ["finish"]=> string(8) "09:30:00" } [0]=> array(2) { ["start"]=> string(8) "10:00:00" ["finish"]=> string(8) "10:30:00" } [1]=> array(2) { ["start"]=> string(8) "11:00:00" ["finish"]=> string(8) "11:00:00" } [2]=> array(2) { ["start"]=> string(8) "12:00:00" ["finish"]=> string(8) "12:30:00" } } </pre>