3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ [ 'ID' => 16, 'begin_date' => new \DateTime('2016-01-01 UTC'), 'end_date' => new \DateTime('2016-11-30 UTC'), ], [ 'ID' => 33, 'begin_date' => new \DateTime('2015-01-04 UTC'), 'end_date' => new \DateTime('2016-02-29 UTC'), ], ]; usort($data, function($a, $b) { // Note PHP 7 <=> doesn't work on \DateTime if($a['end_date'] == $b['end_date']) { return 0; } return $a['end_date'] > $b['end_date'] ? 1 : -1; }); var_dump($now); var_dump($data); // for programs that run over multiple seconds this makes sure we don't drift during sorting $now = new \DateTime('now'); // pick the first element that meets the criteria foreach($data as $index => $element) { if($element['begin_date'] < $now) { // first condition is invalidated echo "begin_date invalidated ID #".$element['ID'].PHP_EOL; continue; } else { var_dump($element); } }
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Undefined variable $now in /in/pFghr on line 25 NULL array(2) { [0]=> array(3) { ["ID"]=> int(33) ["begin_date"]=> object(DateTime)#3 (3) { ["date"]=> string(26) "2015-01-04 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } ["end_date"]=> object(DateTime)#4 (3) { ["date"]=> string(26) "2016-02-29 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } } [1]=> array(3) { ["ID"]=> int(16) ["begin_date"]=> object(DateTime)#1 (3) { ["date"]=> string(26) "2016-01-01 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } ["end_date"]=> object(DateTime)#2 (3) { ["date"]=> string(26) "2016-11-30 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } } } begin_date invalidated ID #33 begin_date invalidated ID #16

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
58.79 ms | 403 KiB | 8 Q