3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $sc = 'hello 8491241 some text 6254841 some text 568241 414844:412'; preg_match_all('/([0-9]{5,10})(:[0-9]{1,5})?/', $sc, $matches, PREG_SET_ORDER); $all_matches = array_reduce($matches, function (array $all, array $match) { $all[] = ['batch' => $match[1], 'type' => '1']; if (isset($match[2])) { $all[] = ['batch' => $match[0], 'type' => '2']; } return $all; }, []); print_r($all_matches);
based on jJRci
Output for 5.4.0 - 7.2.0
Array ( [0] => Array ( [batch] => 8491241 [type] => 1 ) [1] => Array ( [batch] => 6254841 [type] => 1 ) [2] => Array ( [batch] => 568241 [type] => 1 ) [3] => Array ( [batch] => 414844 [type] => 1 ) [4] => Array ( [batch] => 414844:412 [type] => 2 ) )
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/VhM7G on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/VhM7G on line 6
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 T_FUNCTION in /in/VhM7G on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/VhM7G on line 6
Process exited with code 255.