<?php
$sales_people = array(
'2' => array(
'states' => array('NY', 'NJ', 'CT', 'MA', 'VT', 'ME'),
'codes' => array('CA1', 'US7', 'UT9')
),
'5' => array(
'states' => array('FL', 'GA', 'SC', 'NC', 'TN'),
'codes' => array('VA4', 'VA8', 'VA3')
)
);
function searchSubsets($sets, $needle): ?int
{
foreach ($sets as $id => $haystacks) {
foreach ($haystacks as $haystack) {
if (in_array($needle, $haystack)) {
return $id;
}
}
}
return null;
}
var_export(searchSubsets($sales_people, 'CT'));
- Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- 2
preferences:
74.78 ms | 402 KiB | 62 Q