<?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";
- Output for 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
- cheese, mayo
tomato, lettuce
onion
preferences:
138.83 ms | 407 KiB | 5 Q