Question

I have an php array of 99 numbers.

The array contains the digits 1 to 100 with one digit missing.

How to know the missing number?

Was it helpful?

Solution

Since you say you've found an answer yourself, here is a possible solution

$assignmentArray = array(1,2,3,4,5,6,7,8,10);

// find the missing fie... err.. missing value is actually more correct.
$missingNumber = array_sum(range(1, 10)) - array_sum($assignmentArray);
echo 'The missing number is: ' . $missingNumber;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top