Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

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
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Artificial Intelligence