0;$n--) { $pos = $nums[$n]; if($pos > $tail) { break; } $tail = $pos; } echo $n; echo PHP_EOL;