3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $arr = array("station8", "2ndExit", "block9a", "floor5"); echo "<pre>" . __FILE__ . '-->' . __METHOD__ . ':' . __LINE__ . PHP_EOL; var_dump(minMaxNum($arr)); die(); function minMaxNum ($arr = array()) { $min = $max = null; foreach ($arr as $value) { $value = preg_split('/(?<=\d)(?=[a-zA-Z])|(?<=[a-zA-Z])(?=\d)/i', $value); $value = array_filter($value, function ($n){ if(!is_numeric($n)) { unset($n); } else { return $n; } }); foreach($value as $item) { if($min == null && $max == null) { // not initiated $min = $max = $item; } else { if($item < $min) $min = $item; if($item > $max) $max = $item; } } } echo "<pre>" . __FILE__ . '-->' . __METHOD__ . ':' . __LINE__ . PHP_EOL; var_dump($min, $max); die(); }
based on 9PqZA
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.0 - 7.3.0beta1
<pre>/in/Qb6Y7-->:5 <pre>/in/Qb6Y7-->minMaxNum:29 string(1) "2" string(1) "9"