Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize | SQLize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

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"; } } }
Copy Clear