3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function scholar_parse_time($time) { if (preg_match('/^\s*(?P<hour>\d+)(?>:(?P<minute>\d+))(?>:(?P<second>\d+(\.\d*)?))?\s*$/', $time, $match)) { $h = intval($match['hour']); $m = isset($match['minute']) ? intval($match['minute']) : null; $s = isset($match['second']) ? floatval($match['second']) : null; $is = null; if ($h < 24 && (null === $m || $m < 60) && (null === $s || $s < 60)) { if (null !== $s) { $is = intval($s); $ms = $s - $is; } return array( 'hour' => $h, 'minute' => $m, 'second' => $is, 'millis' => round($ms * 1000), 'iso' => null === $m ? sprintf('%02d', $h) : (null === $s ? sprintf('%02d:%02d', $h, $m) : sprintf('%02d:%02d:%02d', $h, $m, $s) ), ); } } return false; } var_dump(scholar_parse_time('0:1')); var_dump(scholar_parse_time('0:1:1')); var_dump(scholar_parse_time('0:1:1.1')); var_dump(scholar_parse_time('0:1:1.'));
Output for 5.0.4 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Notice: Undefined variable: ms in /in/mcBN7 on line 20 array(5) { ["hour"]=> int(0) ["minute"]=> int(1) ["second"]=> NULL ["millis"]=> float(0) ["iso"]=> string(5) "00:01" } array(5) { ["hour"]=> int(0) ["minute"]=> int(1) ["second"]=> int(1) ["millis"]=> float(0) ["iso"]=> string(8) "00:01:01" } array(5) { ["hour"]=> int(0) ["minute"]=> int(1) ["second"]=> int(1) ["millis"]=> float(100) ["iso"]=> string(8) "00:01:01" } array(5) { ["hour"]=> int(0) ["minute"]=> int(1) ["second"]=> int(1) ["millis"]=> float(0) ["iso"]=> string(8) "00:01:01" }
Output for 4.3.3 - 5.0.3
Notice: Undefined variable: ms in /in/mcBN7 on line 20 array(5) { ["hour"]=> int(0) ["minute"]=> int(1) ["second"]=> NULL ["millis"]=> float(0) ["iso"]=> string(5) "00:01" } array(5) { ["hour"]=> int(0) ["minute"]=> int(1) ["second"]=> int(1) ["millis"]=> float(0) ["iso"]=> string(8) "00:01:01" } array(5) { ["hour"]=> int(0) ["minute"]=> int(1) ["second"]=> int(1) ["millis"]=> float(100) ["iso"]=> string(8) "00:01:01" } array(5) { ["hour"]=> int(0) ["minute"]=> int(1) ["second"]=> int(1) ["millis"]=> float(0) ["iso"]=> string(8) "00:01:01" }
Output for 4.3.0 - 4.3.2
Notice: Undefined index: hour in /in/mcBN7 on line 6 Notice: Undefined variable: ms in /in/mcBN7 on line 20 array(5) { ["hour"]=> int(0) ["minute"]=> NULL ["second"]=> NULL ["millis"]=> float(0) ["iso"]=> string(2) "00" } Notice: Undefined index: hour in /in/mcBN7 on line 6 Notice: Undefined variable: ms in /in/mcBN7 on line 20 array(5) { ["hour"]=> int(0) ["minute"]=> NULL ["second"]=> NULL ["millis"]=> float(0) ["iso"]=> string(2) "00" } Notice: Undefined index: hour in /in/mcBN7 on line 6 Notice: Undefined variable: ms in /in/mcBN7 on line 20 array(5) { ["hour"]=> int(0) ["minute"]=> NULL ["second"]=> NULL ["millis"]=> float(0) ["iso"]=> string(2) "00" } Notice: Undefined index: hour in /in/mcBN7 on line 6 Notice: Undefined variable: ms in /in/mcBN7 on line 20 array(5) { ["hour"]=> int(0) ["minute"]=> NULL ["second"]=> NULL ["millis"]=> float(0) ["iso"]=> string(2) "00" }