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'); $tab ['7'] = array('start'=>'14:00:00','finish'=>'14:30:00'); echo "avant tri <pre>"; print_r($tab); echo "</pre>"; uasort($tab, 'sortDurations' ); echo "apres tri <pre>"; var_dump($tab); echo "</pre>"; echo json_encode($tab); ?>
Output for 5.2.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 ) [7] => Array ( [start] => 14:00:00 [finish] => 14:30:00 ) ) </pre>apres tri <pre>array(6) { [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" } [7]=> array(2) { ["start"]=> string(8) "14:00:00" ["finish"]=> string(8) "14:30:00" } } </pre>{"3":{"start":"08:00:00","finish":"08:30:00"},"4":{"start":"09:00:00","finish":"09:30:00"},"0":{"start":"10:00:00","finish":"10:30:00"},"1":{"start":"11:00:00","finish":"11:00:00"},"2":{"start":"12:00:00","finish":"12:30:00"},"7":{"start":"14:00:00","finish":"14:30:00"}}
Output for 5.0.0 - 5.1.6
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 ) [7] => Array ( [start] => 14:00:00 [finish] => 14:30:00 ) ) </pre>apres tri <pre>array(6) { [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" } [7]=> array(2) { ["start"]=> string(8) "14:00:00" ["finish"]=> string(8) "14:30:00" } } </pre> Fatal error: Call to undefined function json_encode() in /in/YZ3nI on line 39
Process exited with code 255.
Output for 4.4.5 - 4.4.9
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 ) [7] => Array ( [start] => 14:00:00 [finish] => 14:30:00 ) ) </pre>apres tri <pre>array(6) { [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" } [7]=> array(2) { ["start"]=> string(8) "14:00:00" ["finish"]=> string(8) "14:30:00" } } </pre> Fatal error: Call to undefined function: json_encode() in /in/YZ3nI on line 39
Process exited with code 255.
Output for 4.3.2 - 4.4.4
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 ) [7] => Array ( [start] => 14:00:00 [finish] => 14:30:00 ) ) </pre>apres tri <pre>array(6) { [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" } [7]=> array(2) { ["start"]=> string(8) "14:00:00" ["finish"]=> string(8) "14:30:00" } } </pre> Fatal error: Call to undefined function: json_encode() in /in/YZ3nI on line 39
Process exited with code 255.
Output for 4.3.0 - 4.3.1
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 ) [7] => Array ( [start] => 14:00:00 [finish] => 14:30:00 ) ) </pre>apres tri <pre>array(6) { [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" } [7]=> array(2) { ["start"]=> string(8) "14:00:00" ["finish"]=> string(8) "14:30:00" } } </pre> Fatal error: Call to undefined function: json_encode() in /in/YZ3nI on line 39