You could sort the strings by length using for example usort and get the first item using reset.
$array = array(
'Google',
'Facebook',
'Twitter',
'Slack',
'Twilio',
);
usort($array, function ($a, $b) {
return strlen($a) < strlen($b);
});
echo reset($array); // Facebook
If there could be more strings with equal length, you could use a foreach and break out of the loop when the length is not equal to the current length of the item to prevent looping the whole list.
$item = reset($array);
$result = [];
if ($item) {
$len = strlen($item);
foreach($array as $value) {
if (strlen($value) === $len) {
$result[] = $value;
continue;
}
break;
}
}
print_r($result);
Result
Array
(
[0] => Facebook
[1] => Test1112
)
Php demo