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";
Output for git.master, git.master_jit, rfc.property-hooks
2 is the first missing number 1 is the first missing number 7 is the first missing number

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
65.48 ms | 401 KiB | 8 Q