3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array = array( 'Google', 'Facebook', 'Twitter', 'Slack', 'Twilio', 'Bookface' ); $cachedLength = 0; foreach ($array as $value) { $currentLength = strlen($value); if ($currentLength > $cachedLength) { $longest = [$value]; $cachedLength = $currentLength; } elseif ($currentLength == $cachedLength) { $longest[] = $value; } } var_export($longest);

preferences:
94.17 ms | 1599 KiB | 5 Q