<?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);
You have javascript disabled. You will not be able to edit any code.