programming-examples/php/Basics/PHP program to find a missing number(s) from an array.php

14 lines
370 B
PHP
Raw Permalink Normal View History

2019-11-18 14:44:36 +01:00
function missing_number($num_list)
{
// construct a new array
$new_arr = range($num_list[0],max($num_list));
// use array_diff to find the missing elements
return array_diff($new_arr, $num_list);
}
print_r(missing_number(array(1,2,3,6,7,8)));
print_r(missing_number(array(10,11,12,14,15,16,17)));
?>