The code explains to find the max and min number, However, I passed an array on the function But the output doesn't seem to appear on the browser, It's blank. I assume the Logic is 100% fine. Also, I would like someone to teach me the syntax of how to pass arrays in a function. Because I have trouble passing array values in PHP. A solution would be great
<?php
$test=array(9,7,3,13,1); // sample array
function maximum($array) // function to find maximum value in an array
{
$slot=$array[0]; // fixed the first value of the array
$length=count($array); // length of the array
for($i=1; $i<$length; $i++)
{
$slot = ($slot<$array[$i]) ? $array[$i] : " "; // comparing the fixed value with other values
}
echo $slot."<br>"; // final max value
}
function minimum($array) // function to find minimum value in an array
{
$slot=$array[0]; // fixed the first value of the array
$length=count($array); // length of the array
for($i=1; $i<$length; $i++)
{
$slot= ($slot>$array[$i]) ? $array[$i] : " "; // comparing the fixed value with other values
}
echo $slot; // final max value
}
echo maximum($test); //passing the $test array to find the max
echo minimum($test); //passing the $test array to find the min
?>