3v4l.org

run code in 300+ PHP versions simultaneously
<?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);
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
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.1.6, 5.2.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.3.11, 4.4.0 - 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.

preferences:
314.9 ms | 401 KiB | 422 Q