3v4l.org

run code in 300+ PHP versions simultaneously
<?php $subject = 'in the middle 9850112686331(14-15) for Rocco A & Stephanie'; $arr = explode(' ', $subject); $candidates = []; for ($i = 0; $i < count($arr); $i++) { for ($j = $i; $j < count($arr); $j++) { $candidates[] = implode(' ', array_slice($arr, $i, $j - $i + 1)); } } usort($candidates, function($a, $b) { return strlen($b) - strlen($a); }); foreach($candidates as $candidate){ echo $candidate . PHP_EOL; }

preferences:
39.19 ms | 402 KiB | 5 Q