- var_export: documentation ( source)
- array_shift: documentation ( source)
- str_replace: documentation ( source)
- preg_grep: documentation ( source)
<?php
$input = [
"Lincoln Crown",
"Crown Court",
"go holiday",
"house fire",
"John Hinton",
"Hinton Jailed"
];
$output = [];
while ($input) {
$output[] = $words = array_shift($input);
$input = preg_grep('~\b(?:\Q' . str_replace(' ', '\E|\Q', $words) . '\E)\b~', $input, PREG_GREP_INVERT);
}
var_export($output);