3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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('2016-01-04 UTC'), 'end_date' => new \DateTime('2016-02-29 UTC'), ], ]; // for programs that run over multiple seconds this makes sure we don't drift during sorting $now = new \DateTime(strtotime('now')); // assume length >= 1 w/ previous validation // keep track of the in-progress leading element, assuming the first is leading to begin with $currentLeading = $data[0]; foreach($data as $index => $element) { if($element['begin_date'] > $now) { // first condition is true if ($index == 0) { echo "Error: Element cannot be the leading element"; // more likely return false if wrapped in a validation function } if($element['end_date'] > $now) { if ($element['end_date'] > $currentLeading['end_date']) { $currentLeading = $element; } } } } var_dump($currentLeading);
based on I8nXC
Output for 7.0.20 - 7.2.0
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (1451991573) at position 8 (7): Unexpected character in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991573') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 7.0.6
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (1463829648) at position 8 (4): Unexpected character in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1463829648') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 7.0.5
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (1459668181) at position 8 (8): Unexpected character in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1459668181') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 7.0.4
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (1457641768) at position 8 (6): Unexpected character in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1457641768') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 7.0.3
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (1458337996) at position 7 (9): Unexpected character in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1458337996') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 7.0.2
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (1458705989) at position 8 (8): Unexpected character in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1458705989') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 7.0.1
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (1458803631) at position 8 (3): Unexpected character in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1458803631') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 7.0.0
Fatal error: Uncaught Exception: DateTime::__construct(): Failed to parse time string (1459066033) at position 7 (0): Unexpected character in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1459066033') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.6.28
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991573) at position 8 (7): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991573') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.6.21
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1462198563) at position 7 (5): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1462198563') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.6.20
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1460269498) at position 7 (4): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1460269498') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.5.30, 5.6.19
Error: Element cannot be the leading elementarray(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" } }
Output for 5.6.18
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1458048883) at position 7 (8): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1458048883') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.5.31, 5.5.33, 5.6.17
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" } }
Output for 5.6.16
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1459155387) at position 7 (3): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1459155387') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.6.15
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1459244743) at position 7 (7): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1459244743') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.6.14
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1460647693) at position 8 (9): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1460647693') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.6.13
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1460736435) at position 8 (3): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1460736435') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.6.12
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1461134184) at position 7 (1): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1461134184') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.6.11
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1461502933) at position 8 (3): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1461502933') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.6.10
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1461596899) at position 8 (9): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1461596899') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.6.9
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1461789243) at position 8 (4): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1461789243') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.6.8
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1461992663) at position 8 (6): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1461992663') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.5.35
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1463962168) at position 8 (6): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1463962168') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.5.34
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1460363924) at position 7 (9): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1460363924') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.5.32
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1458235864) at position 7 (8): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1458235864') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.5.29
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1460874301) at position 8 (0): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1460874301') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.5.28
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1461232483) at position 7 (4): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1461232483') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.5.27
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1461324809) at position 7 (8): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1461324809') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.5.26
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1461692923) at position 8 (2): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1461692923') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.5.25
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1461892454) at position 8 (5): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1461892454') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.5.24
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1464075462) at position 7 (4): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1464075462') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.45
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991577) at position 8 (7): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991577') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.44
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991578) at position 8 (7): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991578') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.41 - 5.4.43
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991580) at position 8 (8): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991580') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.40
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991581) at position 8 (8): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991581') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.39
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991582) at position 8 (8): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991582') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.36 - 5.4.38
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991583) at position 8 (8): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991583') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.34 - 5.4.35
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991584) at position 8 (8): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991584') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.31 - 5.4.32
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991585) at position 8 (8): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991585') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.26 - 5.4.30
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991586) at position 8 (8): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991586') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.23 - 5.4.25
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991587) at position 8 (8): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991587') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.20 - 5.4.22
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991588) at position 8 (8): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991588') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.17 - 5.4.19
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991589) at position 8 (8): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991589') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.13 - 5.4.16
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991590) at position 8 (9): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991590') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.4.11 - 5.4.12
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (1451991591) at position 8 (9): Unexpected character' in /in/048kZ:17 Stack trace: #0 /in/048kZ(17): DateTime->__construct('1451991591') #1 {main} thrown in /in/048kZ on line 17
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/048kZ on line 3
Process exited with code 255.