min


php128 apg

FIND the lowest value.





Be careful when passing arguments with mixed types values because this function can produce unpredictable results.

If the first and only parameter is an ARRAY, this function returns the lowest value in that ARRAY.

If at least two parameters are provided, this function returns the smallest of these values.

Values of different types will be compared using the standard comparison rules.

For instance, a non-numeric STRING will be compared to an integer as though it were 0, but multiple non-numeric STRING values will be compared alphanumerically.

The actual value returned will be of the original type with no conversion applied.

If an empty array is passed, then FALSE will be returned and an E_WARNING error will be emitted.



<?php

mix min 
( array $values )
 

where,

$values An ARRAY containing the values

?>
 

$values


The ARRAY containing the values.



<?php

mix min 
mixed $value1 [, mixed $value2, ..., mix valueN ] )
 

where,

$value1 The first comparable value

$value2 
The second comparable value

. . . . . . . . . . .

$valueN The last comparable value

?>
 

$value1


The first comparable value.



$value2


The second comparable value.



$valueN


The last comparable value.



  1 EXERCISE   

<?php

$arr01 
= [ => 0.112=> 0.002
                
=> 1.532=> 1=> 2=> 3.0E-6 ];

$min01 min($arr01);

echo 
'ARRAY of values to test:<br><pre>';
print_r($arr01);
echo 
'</pre><br>The smallest value is ';
var_export($min01);
echo 
'.';

?> 

 RESULT   

ARRAY of values to test

Array
(
[1] => 0.112
[2] => 0.002
[3] => 1.532
[4] => 1
[5] => 2
[6] => 3.0E-6
)

The smallest value is 3.0000000000000001E-6.


  2 EXERCISE   

<?php

$arr02a 
= [ => 0.112=> 0.002
                  
=> 1.532=> 1=> 2=> 3.0E-6 ];

$arr02b = [ 3691215 ];

$min02 min($arr02a$arr02b);

echo 
'ARRAY of values to test:<br><pre>';
print_r($arr02a);
echo 
'<br>';
print_r($arr02b);
echo 
'</pre><br>The minimum value is<br>';
print_r($min02);
echo 
'.';

?> 

 RESULT   

ARRAY of values to test

Array
(
[1] => 0.112
[2] => 0.002
[3] => 1.532
[4] => 1
[5] => 2
[6] => 3.0E-6
)

Array
(
[0] => 3
[1] => 6
[2] => 9
[3] => 12
[4] => 15
)

The minimum value is

Array ( [0] => 3 [1] => 6 [2] => 9 [3] => 12 [4] => 15 )