note 87730 added to function.max
| From: | McCookieM at osu1 dot php dot net | Date: | Thu, 18 Dec 2008 15:26:58 +0000 |
| Subject: | note 87730 added to function.max | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-148317@lists.php.net to get a copy of this message | ||
Just discovered that max() can find the longest strings in an array of strings.
<?php
$test=array("a","bc","def","ghij","kl","mno");
echo 'Longest string in test array is : '.max($test);
?>
Will output :
Longest string in test array is : ghij
This appears to take the first occurance of the longest string so if we added "pqrs" to
the end of the array is would still return "ghij".
This wasn't clear but kind of hinted at in the function description.
Obviously, this also works for min() for the shortest string.
----
Server IP: 92.48.74.199
Probable Submitter: 81.139.57.163
----
Manual Page -- http://www.php.net/manual/en/function.max.php
Edit -- https://master.php.net/note/edit/87730
Del: integrated -- https://master.php.net/note/delete/87730/integrated
Del: useless -- https://master.php.net/note/delete/87730/useless
Del: bad code -- https://master.php.net/note/delete/87730/bad+code
Del: spam -- https://master.php.net/note/delete/87730/spam
Del: non-english -- https://master.php.net/note/delete/87730/non-english
Del: in docs -- https://master.php.net/note/delete/87730/in+docs
Del: other reasons-- https://master.php.net/note/delete/87730
Reject -- https://master.php.net/note/reject/87730
Search -- https://master.php.net/manage/user-notes.php