3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "00 a 51 - a9"; $numbers = ""; $chars = ""; preg_match("/(\d*)(\D*)/", $string, $matches); print_r($matches); foreach($matches[1] as $match) { $numbers .= is_int($match) ? $match : ''; } foreach($matches[2] as $match) { $chars .= !is_int($match) ? $match : ''; } var_dump($numbers); echo " "; var_dump($chars);
Output for 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] => 00 a [1] => 00 [2] => a ) Warning: foreach() argument must be of type array|object, string given in /in/RECbB on line 9 Warning: foreach() argument must be of type array|object, string given in /in/RECbB on line 13 string(0) "" string(0) ""
Output for 4.3.0 - 4.3.10, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33
Array ( [0] => 00 a [1] => 00 [2] => a ) Warning: Invalid argument supplied for foreach() in /in/RECbB on line 9 Warning: Invalid argument supplied for foreach() in /in/RECbB on line 13 string(0) "" string(0) ""
Output for 4.3.11
Array ( [0] => 00 a [1] => 00 [2] => a ) string(0) "" string(0) ""

preferences:
204.27 ms | 401 KiB | 312 Q