'Printing numers without using PHP inbuild functions
$numbers = array(3,5,6,7,8,11);
$missing = array();
for ($i = 3; $i < 11; $i++) {
if (!in_array($i, $numbers)){
$missing[] = $i;
}
}
I want to find the missing numbers from 3 to 11 without using PHP innuild function, i have tried but i haven't not completed fully.
In this code i have used in_array but without this i have to do. any one help here.I am new to PHP using PHP inbuild i can do this, but this is not my case.
Solution 1:[1]
you can use array_diff same as :
$numbersOrigin = range(3, 11);
$numbers = array(3,5,6,7,8,11);
$missing = array_diff($numbersOrigin, $numbers);
unuse buildIn functions :
$numbers = array(3,5,6,7,8,11);
$missing = array();
$index = 0;
for ($i = 3; $i < 11; $i++) {
if ($numbers[$index] === $i) {
$index++;
} else {
$missing[] = $i;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
