<?php
function filter_ingredients($elements) {
return implode(', ', array_filter(preg_split('/,\s*/', $elements), function ($v) {
return !preg_match('/^no\b/', $v);
}));
}
echo filter_ingredients("cheese, no tomato, no onion, mayo, no lettuce") . "\n";
echo filter_ingredients("no cheese, tomato, no onion, no mayo, lettuce") . "\n";
echo filter_ingredients("no cheese, no tomato, onion, no mayo, no lettuce") . "\n";
preferences:
25.61 ms | 407 KiB | 5 Q