3v4l.org

run code in 300+ PHP versions simultaneously
<?php $keywords = ['Paso', 'Robles']; $columns = ['ID', 'StorageArea', 'Size', 'Winery', 'Brand', 'Appellation', 'ReleaseYear', 'Varietal', 'Status', 'CountryName']; $where = 'WHERE ' . implode("\nAND ", array_map(function ($keyword) use ($columns) { $keyword = str_replace("'", "''", $keyword); return "\n(" . implode(' OR ', array_map(function ($column) use ($keyword) { return "\n`$column` LIKE '%$keyword%'"; }, array_filter($columns, function ($column) { return $column !== 'ID'; }))) . "\n)"; }, $keywords)); echo $where;
Output for 7.1.25 - 7.1.27, 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.29, 8.2.0 - 8.2.20, 8.3.0 - 8.3.8
WHERE ( `StorageArea` LIKE '%Paso%' OR `Size` LIKE '%Paso%' OR `Winery` LIKE '%Paso%' OR `Brand` LIKE '%Paso%' OR `Appellation` LIKE '%Paso%' OR `ReleaseYear` LIKE '%Paso%' OR `Varietal` LIKE '%Paso%' OR `Status` LIKE '%Paso%' OR `CountryName` LIKE '%Paso%' ) AND ( `StorageArea` LIKE '%Robles%' OR `Size` LIKE '%Robles%' OR `Winery` LIKE '%Robles%' OR `Brand` LIKE '%Robles%' OR `Appellation` LIKE '%Robles%' OR `ReleaseYear` LIKE '%Robles%' OR `Varietal` LIKE '%Robles%' OR `Status` LIKE '%Robles%' OR `CountryName` LIKE '%Robles%' )

preferences:
142 ms | 404 KiB | 164 Q