max


php128 apg

FIND the highest 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 highest value in that ARRAY.

If at least two parameters are provided, this function returns the biggest 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 max 
( array $values )
 

where,

$values An ARRAY containing the values

?>
 

$values


The ARRAY containing the values.



<?php

mix max 
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 ];

$max01 max($arr01);

echo 
'ARRAY of values to test:<br><pre>';
print_r($arr01);
echo 
'</pre><br>The maximum value is ';
var_export($max01);
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 maximun value is 2.


  2 EXERCISE   

<?php

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

$arr02b = [ 3691215 ];

$max02 max($arr02a$arr02b);

echo 
'ARRAY of values to test:<br><pre>';
print_r($arr02a);
echo 
'<br>';
print_r($arr02b);
echo 
'</pre><br>The maximum value is<br>';
print_r($max02);
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 maximum value is

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