note 88475 added to function.max
| From: | int at mage dot ich | Date: | Mon, 26 Jan 2009 15:19:55 +0000 |
| Subject: | note 88475 added to function.max | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149774@lists.php.net to get a copy of this message | ||
To sumeruter+php add an at gmail dot com: This is not functional for all arrays - not always is
returned the highest value. For example:
<?php
$array = Array (
"first" => Array(
0 => 19,
1 => 41,
2 => 7,
3 => 21,
4 => 32,
),
"second" => Array (
0 => 8,
1 => 84,
2 => 63,
3 => 61,
4 => 100,
));
ECHO max(max($array)); // = 41
?>
It will return 41 instead of expected 100. It's because the array is compared from left to
right, as is written in manual:
$array["first"][0] > $array["second"][0] ? RETURN
$array["first"][0] : RETURN $array["second"][0]
Which sub-array is returned depends only on the first values of them.
----
Server IP: 212.24.129.51
Probable Submitter: 213.155.231.66
----
Manual Page -- http://www.php.net/manual/en/function.max.php
Edit -- https://master.php.net/note/edit/88475
Del: integrated -- https://master.php.net/note/delete/88475/integrated
Del: useless -- https://master.php.net/note/delete/88475/useless
Del: bad code -- https://master.php.net/note/delete/88475/bad+code
Del: spam -- https://master.php.net/note/delete/88475/spam
Del: non-english -- https://master.php.net/note/delete/88475/non-english
Del: in docs -- https://master.php.net/note/delete/88475/in+docs
Del: other reasons-- https://master.php.net/note/delete/88475
Reject -- https://master.php.net/note/reject/88475
Search -- https://master.php.net/manage/user-notes.php