max
Description
Syntax
max(
mixed $value,
mixed ...$values
): mixedmax(
array $value_array
): mixedParameters
value
Any comparable value.
values
Any comparable values.
value_array
An array containing the values.
Return
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.
Examples
1 · value values
<? $value = 0; $values1 = 1; $values2 = 2; $values3 = 3; $return = max($value, $values1, $values2, $values3); echo $return;
3
2 · value_array
<?
$value_array =
[
0,
1,
2,
3
];
$return = max($value_array);
echo $return;
3
3 · false < true
<? $value = false; $values = true; $return = max($value, $values); var_dump($return);
bool(true)
4 · = · first
<? $value = 0; $values = false; $return = max($value, $values); var_dump($return);
int(0)
5 · = · first
<? $value = false; $values = 0; $return = max($value, $values); var_dump($return);
bool(false)
6 · array · length
<?
$value =
[
1,
2,
3
];
$values =
[
10,
20
];
$return = max($value, $values);
print_r($return);
Array
(
[0] => 1
[1] => 2
[2] => 3
)
7 · array · left to right
<?
$value =
[
1,
20,
30
];
$values =
[
10,
2,
3
];
$return = max($value, $values);
print_r($return);
Array
(
[0] => 10
[1] => 2
[2] => 3
)
8 · non-array < array
<?
$value = 10;
$values1 = "20";
$values2 =
[
0,
1
];
$return = max($value, $values1, $values2);
print_r($return);
Array
(
[0] => 0
[1] => 1
)