3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $array = array(array('date'=>'2014-12-01', 'price'=>'123.00'), array('date'=>'2013-12-01', 'price'=>'123.00'), array('date'=>'2014-02-01', 'price'=>'123.00'), array('date'=>'2014-03-01', 'price'=>'123.00')); var_dump($array); function sortByDate($a, $b) { $datetime1 = date_create($a); $datetime2 = date_create($b); $interval = date_diff($datetime1, $datetime2); $diff = $interval->format('%a'); if($diff>0){return 1;} if($diff<0){return -1;} if($diff==0){return 0;} return false; } usort($array, 'sortByDate'); var_dump($array);
Output for 7.0.0 - 7.1.0
array(4) { [0]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } } Warning: date_create() expects parameter 1 to be string, array given in /in/D5Blc on line 7 Warning: date_create() expects parameter 1 to be string, array given in /in/D5Blc on line 8 Warning: date_diff() expects parameter 1 to be DateTimeInterface, boolean given in /in/D5Blc on line 9 Fatal error: Uncaught Error: Call to a member function format() on boolean in /in/D5Blc:10 Stack trace: #0 [internal function]: sortByDate(Array, Array) #1 /in/D5Blc(17): usort(Array, 'sortByDate') #2 {main} thrown in /in/D5Blc on line 10
Process exited with code 255.
Output for 5.6.0 - 5.6.28
array(4) { [0]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } } Warning: date_create() expects parameter 1 to be string, array given in /in/D5Blc on line 7 Warning: date_create() expects parameter 1 to be string, array given in /in/D5Blc on line 8 Warning: date_diff() expects parameter 1 to be DateTimeInterface, boolean given in /in/D5Blc on line 9 Fatal error: Call to a member function format() on boolean in /in/D5Blc on line 10
Process exited with code 255.
Output for 5.5.8 - 5.5.38
array(4) { [0]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } } Warning: date_create() expects parameter 1 to be string, array given in /in/D5Blc on line 7 Warning: date_create() expects parameter 1 to be string, array given in /in/D5Blc on line 8 Warning: date_diff() expects parameter 1 to be DateTimeInterface, boolean given in /in/D5Blc on line 9 Fatal error: Call to a member function format() on a non-object in /in/D5Blc on line 10
Process exited with code 255.
Output for 5.3.0 - 5.5.7
array(4) { [0]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } } Warning: date_create() expects parameter 1 to be string, array given in /in/D5Blc on line 7 Warning: date_create() expects parameter 1 to be string, array given in /in/D5Blc on line 8 Warning: date_diff() expects parameter 1 to be DateTime, boolean given in /in/D5Blc on line 9 Fatal error: Call to a member function format() on a non-object in /in/D5Blc on line 10
Process exited with code 255.
Output for 5.2.0 - 5.2.17
array(4) { [0]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } } Warning: date_create() expects parameter 1 to be string, array given in /in/D5Blc on line 7 Warning: date_create() expects parameter 1 to be string, array given in /in/D5Blc on line 8 Fatal error: Call to undefined function date_diff() in /in/D5Blc on line 9
Process exited with code 255.
Output for 5.0.0 - 5.1.6
array(4) { [0]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } } Fatal error: Call to undefined function date_create() in /in/D5Blc on line 7
Process exited with code 255.
Output for 4.4.5 - 4.4.9
array(4) { [0]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } } Fatal error: Call to undefined function: date_create() in /in/D5Blc on line 7
Process exited with code 255.
Output for 4.3.2 - 4.4.4
array(4) { [0]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } } Fatal error: Call to undefined function: date_create() in /in/D5Blc on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1
array(4) { [0]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } } Fatal error: Call to undefined function: date_create() in /in/D5Blc on line 7