3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ "Lincoln Crown", "Crown Court", "go holiday", "house fire", "John Hinton", "Hinton Jailed" ]; $output = []; $blacklist = []; foreach ($input as $string) { if (!$blacklist || !preg_match('/\b(?:' . implode('|', $blacklist) . ')\b/', $string)) { $output[] = $string; } foreach(explode(' ', $string) as $word) { $blacklist[$word] = preg_quote($word); } } var_export($blacklist); echo "\n"; var_export($output);
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array ( 'Lincoln' => 'Lincoln', 'Crown' => 'Crown', 'Court' => 'Court', 'go' => 'go', 'holiday' => 'holiday', 'house' => 'house', 'fire' => 'fire', 'John' => 'John', 'Hinton' => 'Hinton', 'Jailed' => 'Jailed', ) array ( 0 => 'Lincoln Crown', 1 => 'go holiday', 2 => 'house fire', 3 => 'John Hinton', )

preferences:
153.14 ms | 408 KiB | 5 Q