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 date_compare($a, $b) { $t1 = strtotime($a['date']); $t2 = strtotime($b['date']); return $t1 - $t2; } usort($array, 'date_compare'); var_dump($array); function dateCompare($a, $b) { $t1 = strtotime($a); $t2 = strtotime($b); return round(($t1 - $t2)/86400); } var_dump(dateCompare(date(), '2014-03-06'));
Output for 5.1.2 - 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" } } array(4) { [0]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } } Warning: date() expects at least 1 parameter, 0 given in /in/S82G2 on line 22 float(-16135)
Output for 5.1.0 - 5.1.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" } } array(4) { [0]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } } Warning: date() expects at least 1 parameter, 0 given in /in/S82G2 on line 22 float(3)
Output for 5.0.1 - 5.0.5
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" } } array(4) { [0]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } } Warning: Wrong parameter count for date() in /in/S82G2 on line 22 Warning: strtotime(): Called with an empty time parameter. in /in/S82G2 on line 18 float(-16135)
Output for 4.3.2 - 5.0.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" } } array(4) { [0]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } } Warning: Wrong parameter count for date() in /in/S82G2 on line 22 Notice: strtotime(): Called with empty time parameter in /in/S82G2 on line 18 float(3)
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" } } array(4) { [0]=> array(2) { ["date"]=> string(10) "2013-12-01" ["price"]=> string(6) "123.00" } [1]=> array(2) { ["date"]=> string(10) "2014-02-01" ["price"]=> string(6) "123.00" } [2]=> array(2) { ["date"]=> string(10) "2014-03-01" ["price"]=> string(6) "123.00" } [3]=> array(2) { ["date"]=> string(10) "2014-12-01" ["price"]=> string(6) "123.00" } } Warning: Wrong parameter count for date() in /in/S82G2 on line 22 Notice: strtotime() [http://www.php.net/function.strtotime]: Called with empty time parameter in /in/S82G2 on line 18 float(3)