3v4l.org

run code in 300+ PHP versions simultaneously
<?php function find_missing($numeros) { $numeros = array_filter(array_unique($numeros), function ($v) { return $v >= 0; }); sort($numeros); for ($i = 1; $i < count($numeros); $i++) { if ($numeros[$i] != $numeros[$i-1] + 1) { return $numeros[$i-1] + 1; } } // all numbers consecutive return false; } $m = find_missing(array(1, 3, 6, 4)); echo ($m === false) ? "array is consecutive\n" : "$m is the first missing number\n"; $m = find_missing(array(-1,9, 0, 8)); echo ($m === false) ? "array is consecutive\n" : "$m is the first missing number\n"; $m = find_missing(array(1,2,3,4,1,2,3,5,6,3,13,4,6,5, -1, -2)); echo ($m === false) ? "array is consecutive\n" : "$m is the first missing number\n";

preferences:
43.2 ms | 402 KiB | 5 Q