3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array ( 0 => 'ARRELEMENT_test', 1 => 'ARRELEMENT_test_v8', 2 => 'ARRELEMENT_test_v9', 3 => 'ARRELEMENT_test_v1', 4 => 'ARRELEMENT_test_v2', 5 => 'ARRELEMENT_test_v3' ); function getMaxTest($arr){ foreach($arr as $key=>$val){ preg_match('!\d+!', $val, $match); if($match){ $index[$key]= $match[0]; } } arsort($index); reset($index); $first_key = key($index); //var_dump($first_key); return $first_key; } $maxIndex = getMaxTest($arr); echo $arr[$maxIndex]; //die; //natsort($arr); //print_r(end($arr));
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
ARRELEMENT_test_v9

preferences:
119.59 ms | 1404 KiB | 4 Q