i have 7 numbers in random from -100 to 100, from those seven numbers i need to find the biggest diference between each them
example:
-50 , 60 , -4 , 80 , 25, -34, 15
the output will be 130 -50 and 80 is the biggest diference
but i need in php
i have tried echo max(rand(-100, 100));
but it is not the output im looking for
this i tried too:
$myarray = array(
'this' => 2,
'that' => 14,
'them' => -5,
'other' => 200,
'nothing' => 42,
'somethingelse' => 1,
'you' => 10,
'me' => 30);
foreach ($myarray as $key => $value) {
if (!isset ($min) || $value < $min) { $min = $value; }
if (!isset ($max) || $value > $max) { $max = $value; }
}
$diff = $max - $min;
echo $diff;
any suggestion?
Aucun commentaire:
Enregistrer un commentaire