$filter = function(string $input, string $attr) {
return implode(' ', array_reduce(explode(' ', $input), function(array $acc, string $selector) use($attr) {
$acc[str_starts_with($selector, $attr) ? $attr : $selector] = $selector;
return $acc;
}, []));
};
var_dump($filter('any1 col-12 any2 col-4 any3 col-7 other', 'col-'));
var_dump($filter('any1 col-12 any2 col-4 any3 col-7 other col-7 col-7', 'col-'));