PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $products = [ 'smartphone samsung s23', 'smartphone samsung s24', 'tablet samsung s23', 'tablet samsung s24', 'smartphone lg', 'geladeira samsung', 'geladeira lg', 'geladeira brastemp', 'notebook samsung', 'notebook dell' ]; $filters = [ '{smartphone|samsung}', '{s23|tablet}', '{lg}' ]; foreach ($products as $product) { //$terms = preg_split('//', $products, -1, PREG_SPLIT_NO_EMPTY); $terms = preg_split('/\s+/', $product, 0, PREG_SPLIT_NO_EMPTY); //echo implode('|', $terms)."\n\n"; foreach ($filters as $filter) { //if (!array_diff(explode('|', $filter), $terms)) { if (!array_diff(explode('|', str_replace(['{', '}'], '', $filter)), $terms)) { echo $product."\n\n"; } } }
Show:  
Copy Clear