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.