
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
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 Articles
- 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 standard deviation of values within an array
- PHP program to find the sum of cubes of natural numbers that are odd
- Golang Program to Print Odd Numbers Within a Given Range
- PHP program to find the average of the first n natural numbers that are even
- Program to find lowest possible integer that is missing in the array in Python
- Python - Find the number of prime numbers within a given range of numbers
- How to find Kaprekar numbers within a given range using 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
- PHP program to find if a number is present in a given sequence of numbers
- Program to find missing numbers from two list of numbers in Python
- What are the different ways to find missing numbers in a sorted array without any inbuilt functions using C#?

Advertisements