How to find the missing values in a sorted range (x to y) array with PHP

1 Answer

0 votes
$x = 4;
$y = 15;

$lst = [5, 5, 5, 5, 6, 7, 9, 10, 10, 10, 11, 13];

$range = range($x, $y);
$missingValues = array_diff($range, $lst);

echo "missingValues: " . implode(", ", $missingValues);


/*
run:

missingValues: 4, 8, 12, 14, 15

*/

 



answered Oct 26, 2024 by avibootz
...