Find Maximum and Minimum in an Array: Write a PHP function to find the maximum and minimum values in an array.

function findMinMax($arr) {
    $min = min($arr);
    $max = max($arr);
    return ["min" => $min, "max" => $max];
}

// Example usage:
$array = [3, 7, 2, 9, 1, 6];
$result = findMinMax($array);
echo "Minimum value: " . $result["min"] . ", Maximum value: " . $result["max"];

Related Posts

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Artificial Intelligence