Showing posts with label array. Show all posts
Showing posts with label array. Show all posts

Saturday, September 5, 2015

function for min number from array - manually

<?php

function min_number($array){
    $min_number = $array[0];
    $length = count($array);
    for($i = 0; $i < $length; $i++){
        if($min_number > $array[$i]){
           $min_number = $array[$i];
        }
    }
    return $min_number;
}

Friday, August 28, 2015

How to get min number from an array

/*
 * How to get min number from a array
 * */
$numbers = array(9, 0, 1, 77, 4, 5, -1, 10);

$min_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 ($min_number > $numbers[$i]){
       $min_number = $numbers[$i];
   }
}
echo "Min number is the array is ", $min_number;

how to get max number from an array

/*
* 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;

css snippet for blogger code highlighting

code, .code {     display: block;     background: beige;     padding: 10px;     margin: 8px 15px; }