<?php
$dwellingInfo = [
["AAA", "Chimney with red bricks"],
["BBB", "Two wide windows in the main floor"],
["CCC", "Roof tiles renewed in 2015"]
];
$haystack = implode(
',',
array_column($dwellingInfo, 1)
);
$dwellingAttributes = [
["0001", 'Chimney', '/\b(?:Chimney with|Big stove)\b/i'],
["0002", 'Garden', '/\bgarden\b/i'],
["0003", 'Roof tiles', '/\bRoof tiles\b/i'],
["0004", 'Windows', '/\bwindows?\b/i'],
["0005", 'Garage', '/\b(?:garage|car port|under cover area)\b/i']
];
$attributePatterns = [
"0001" => '/\b(?:Chimney with|Big stove)\b/i',
"0002" => '/\bgarden\b/i',
"0003" => '/\bRoof tiles\b/i',
"0004" => '/\bwindows?\b/i',
"0005" => '/\b(?:garage|car port|under cover area)\b/i'
];
foreach ($dwellingAttributes as [$id, $term, $pattern]) {
printf(
"%s - %s - %s\n",
$id,
$term,
preg_match($attributePatterns[$id], $haystack)
? 'available'
: 'unavailable'
);
}
preferences:
24.12 ms | 407 KiB | 5 Q