3v4l.org

run code in 300+ 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:
32.84 ms | 404 KiB | 5 Q