3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array( 'Google', 'Facebook', "Test1112", 'Twitter', 'Slack', 'Twilio' ); usort($array, function ($a, $b) { return strlen($a) < strlen($b); }); $item = reset($array); $result = []; if ($item) { $len = strlen($item); foreach($array as $value) { if (strlen($value) === $len) { $result[] = $value; continue; } break; } } print_r($result);
Output for 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in /in/q5d8X on line 12 Array ( [0] => Facebook [1] => Test1112 )
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Deprecated: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero in /in/q5d8X on line 14 Array ( [0] => Facebook [1] => Test1112 )
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Array ( [0] => Facebook [1] => Test1112 )

preferences:
213.32 ms | 402 KiB | 227 Q