How to use min with an Array In PHP
Creates an array with the numbers and utilizes the min function directly with the array as an argument.
Example: Illustration of Smallest of given two numbers In PHP Using min with an Array.
PHP
<?php $num1 = 10; $num2 = 5; // Use the min function with an array $min = min([ $num1 , $num2 ]); echo "The smallest number is: $min" ; ?> |
Output:
The smallest number is: 5
How to Find the Smallest of given Two Nnumbers In PHP ?
Given two numbers num1 and num2, the task is to find the smallest number between them. Here, we will see the different approaches to solving this problem.
Examples:
Input: 10 5
Ouput: 5
Table of Content
- Using Conditional (Ternary) Operator
- Using if-else Statements
- Using the min Function
- The sort() Method
- Using the spaceship operator (<=>)
- Using min with an Array