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>"; **/ echo json_encode($tab); uasort($tab, 'sortDurations' ); echo "\r\n"; /** echo "apres tri <pre>"; var_dump($tab); echo "</pre>"; **/ echo json_encode($tab); echo "\r\n"; ?>
Output for 5.2.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
{"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"},"3":{"start":"08:00:00","finish":"08:30:00"},"4":{"start":"09:00:00","finish":"09:30:00"},"7":{"start":"14:00:00","finish":"14:30:00"}} {"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
Fatal error: Call to undefined function json_encode() in /in/sgSQ4 on line 33
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: json_encode() in /in/sgSQ4 on line 33
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: json_encode() in /in/sgSQ4 on line 33
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: json_encode() in /in/sgSQ4 on line 33