Minimum element in an array in PHP
Q. Write a PHP program to find the minimum element in an array
<?php
// Define an array
$numbers = array(45, 12, 78, 5, 89, 23, 67);
// Initialize min with the first element
$min = $numbers[0];
// Traverse the array to find the minimum
for ($i = 1; $i < count($numbers); $i++) {
if ($numbers[$i] < $min) {
$min = $numbers[$i];
}
}
// Display the minimum element
echo "The minimum element in the array is: $min";
?>
Q. Write an algorithm to find the minimum element in an array in PHP
1. Start
2. Define an array numbers[]
3. Initialize min = numbers[0]
4. Loop from i = 1 to length of array - 1:
a. If numbers[i] < min, then set min = numbers[i]
5. Print min
6. End
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com