<?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";
You have javascript disabled. You will not be able to edit any code.