Pregunta

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?

¿Fue útil?

Solución

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;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top