max

Find highest value

Syntax

max ( array $values ) : mixed
max ( mixed $value1 [, mixed $... ] ) : mixed

Parameters

values

An array containing the values.

value1

Any comparable value.

...

Any comparable value.

Return

max() returns the parameter value considered "highest" according to standard comparisons. If multiple values of different types evaluate as equal (e.g. 0 and 'abc') the first provided to the function will be returned. If an empty array is passed, then FALSE will be returned and an E_WARNING error will be emitted.

Examples

1 · values

<?

$values = array(1, 2, 3);

$return = max($values);

echo $return;

?>
3

2 · value1 ...

<?

$value1 = 1;
$value2 = 2;
$value3 = 3;

$return = max($value1, $value2, $value3);

echo $return;

?>
3

3 · First

<?

$value1 = 0;
$value2 = false;
$value3 = null;

$return = max($value1, $value2, $value3);

var_dump($return);

?>
int(0)

4 · First

<?

$value1 = 1;
$value2 = true;

$return = max($value1, $value2);

var_dump($return);

?>
int(1)

5 · First

<?

$value1 = 0;
$value2 = "abc";

$return = max($value1, $value2);

echo $return;

?>
abc

6 · Length

<?

$value1 = array(1, 2, 3);
$value2 = array(3, 2);

$return = max($value1, $value2);

print_r($return);

?>
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)

7 · Left to Right

<?

$value1 = array(1, 2, 3);
$value2 = array(3, 2, 1);

$return = max($value1, $value2);

print_r($return);

?>
Array
(
    [0] => 3
    [1] => 2
    [2] => 1
)
HomeMenu