/*
* How to get max number from a array
* */
$numbers = array(9, 0, 1, 77, 4, 5, -1, 10);
$max_number = $numbers[0];
$length = count($numbers);//in order to save time we initial length outside of the loops
for($i = 0; $i < $length; $i++){
if ($max_number < $numbers[$i]){
$max_number = $numbers[$i];
}
}
echo "Max number is the array is ", $max_number;
* How to get max number from a array
* */
$numbers = array(9, 0, 1, 77, 4, 5, -1, 10);
$max_number = $numbers[0];
$length = count($numbers);//in order to save time we initial length outside of the loops
for($i = 0; $i < $length; $i++){
if ($max_number < $numbers[$i]){
$max_number = $numbers[$i];
}
}
echo "Max number is the array is ", $max_number;
No comments:
Post a Comment