# Find value from the while loop

## Recommended Posts

```<?php
function factorial(\$number)
{
if (\$number < 2) {
return 1;
} else {
return (\$number * factorial(\$number-1));
}
}

function poisson(\$occurrence,\$chance)
{
\$e = exp(1);

\$a = pow(\$e, (-1 * \$chance));
\$b = pow(\$chance,\$occurrence);
\$c = factorial(\$occurrence);

return \$a * \$b / \$c;
}

\$x = 2.5;
\$y = 1.5;
\$calAll = array();
for(\$z = 0 ; \$z <= 9 ; \$z++) {
array_push(\$calAll,
(poisson(\$z,\$x) * poisson(0,\$y))*100,
(poisson(\$z,\$x) * poisson(1,\$y))*100,
(poisson(\$z,\$x) * poisson(2,\$y))*100

);
}
\$value = max(\$calAll);
\$key = array_search(\$value, \$calAll);
print_r(\$calAll) . "\n";
echo "max =",\$value , " key =",\$key . "\n";;
?>```

it is possible to find \$z and the number 0,1 or 2 from the max of the returned array ?

I used excel to perform this action and i found that for max=8.5854557290941 the \$z is 2 and number 1 how to achieve this in php ?

##### Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.