- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# PHP program to find the numbers within a given array that are missing

To find the numbers within a given array that are missing, the code is as follows −

## Example

<?php function missing_nums($my_arr, $arr_len, $val) { sort($my_arr); sort($my_arr , $arr_len); $i = 0; while ($i < $n && $my_arr[$i] <= 0) $i++; $count = 0; $current_num = 1; while ($count < $k && $i < $arr_len) { if ($arr[$i] != $current_num) { echo $current_num , " "; $count++; } else $i++; $current_num++; } while ($count < $val) { echo $current_num , " "; $current_num++; $count++; } } $my_arr =array ( 6, 7, 9 ); $arr_len = sizeof($my_arr); $val = 5; print_r("The missing numbers in the array is "); missing_nums($my_arr, $arr_len, $val); ?>

## Output

The missing numbers in the array is 1 2 3 4 5

A function named ‘missing_nums’ is defined that checks to see if a number is missing from an array of continuous numbers. It iterates through the array and checks to see the count and the current_num that is being iterated over. If two values can’t be found when 1 is added to the previous number, it is considered to be missing.

Outside the function, the array is defined, its length is assigned to a variable and the number of missing numbers that need to be found is also defined. The function is called by passing these values as parameters and computed output is displayed on the console.

- Related Questions & Answers
- PHP program to find the first ‘n’ numbers that are missing in an array
- PHP program to find the sum of odd numbers within a given range
- PHP program to find missing elements from an array
- PHP program to find the sum of cubes of natural numbers that are odd
- PHP program to find the average of the first n natural numbers that are even
- Python - Find the number of prime numbers within a given range of numbers
- Golang Program to Print Odd Numbers Within a Given Range
- PHP program to find standard deviation of values within an array
- How to find Kaprekar numbers within a given range using Python?
- Program to find lowest possible integer that is missing in the array in Python
- Write a program in C++ to find the missing positive number in a given array of unsorted integers
- Write a program in Java to find the missing positive number in a given array of unsorted integers
- Program to find missing numbers from two list of numbers in Python
- PHP program to find if a number is present in a given sequence of numbers
- What are the different ways to find missing numbers in a sorted array without any inbuilt functions using C#?

Advertisements