note 89724 added to function.array-flip
| From: | HayleyWatson at osu1 dot php dot net | Date: | Fri, 20 Mar 2009 10:22:10 +0000 |
| Subject: | note 89724 added to function.array-flip | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152191@lists.php.net to get a copy of this message | ||
Finding the longest string in an array?
<?php
function longest_string_in_array($array)
{
$mapping = array_combine($array, array_map('strlen', $array));
return array_keys($mapping, max($mapping));
}
?>
Differences are obvious: returns an array of [i]all[/i] of the longest strings, instead of just
picking one arbitrarily. Doesn't do the stripslashing or magic stuff because that's
another job for for another function.
----
Server IP: 212.199.163.191
Probable Submitter: 114.134.161.9
----
Manual Page -- http://www.php.net/manual/en/function.array-flip.php
Edit -- https://master.php.net/note/edit/89724
Del: integrated -- https://master.php.net/note/delete/89724/integrated
Del: useless -- https://master.php.net/note/delete/89724/useless
Del: bad code -- https://master.php.net/note/delete/89724/bad+code
Del: spam -- https://master.php.net/note/delete/89724/spam
Del: non-english -- https://master.php.net/note/delete/89724/non-english
Del: in docs -- https://master.php.net/note/delete/89724/in+docs
Del: other reasons-- https://master.php.net/note/delete/89724
Reject -- https://master.php.net/note/reject/89724
Search -- https://master.php.net/manage/user-notes.php