Algorithms/Find maximum/Php method 1

From Wikibooks, open books for an open world
Jump to: navigation, search
<?
function findMax($i_intaryTab){
        if(count($i_intaryTab) == 1){
                return $i_intaryTab[0];
        }
        elseif(count($i_intaryTab) == 0){
                return 0;
        }
        else{
                $o_intMax = $i_intaryTab[0];
 
                for($i = 1;$i < count($i_intaryTab);$i++){
                        if($i_intaryTab[$i] >$o_intMax){
                                $o_intMax = $i_intaryTab[$i];
                        }
                }
                return $o_intMax;
        }
}
$testArray = array(4,5,8,7,5,45,5777);
echo findMax($testArray);
?>
Personal tools
Namespaces
Variants
Actions
Navigation
Community
Toolbox
Sister projects
Print/export