3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $begin = 100; $end = 200; $array = [0 => 1, 10 => 2, 50 => 3, 70 => 2, 90 => 3, 110 => 4, 150 => 2, 170 => 3, 180 => 4, 190 => 2]; $array = array_reverse($array, true); $value = 2; $result = []; $prev_time = $end; foreach ($array as $time => $current_value) { if ($current_value == 2) { $result[] = [$time, $prev_time]; } $prev_time = $time; } var_dump($result);
Output for 5.4.0 - 7.2.0
array(4) { [0]=> array(2) { [0]=> int(190) [1]=> int(200) } [1]=> array(2) { [0]=> int(150) [1]=> int(170) } [2]=> array(2) { [0]=> int(70) [1]=> int(90) } [3]=> array(2) { [0]=> int(10) [1]=> int(50) } }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/J0nBn on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/J0nBn on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/J0nBn on line 4
Process exited with code 255.