<?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();
}
- Output for 7.1.0 - 7.1.33, 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.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
- <pre>/in/Qb6Y7-->:5
<pre>/in/Qb6Y7-->minMaxNum:29
string(1) "2"
string(1) "9"
preferences:
160.92 ms | 403 KiB | 185 Q