3v4l.org

run code in 300+ PHP versions simultaneously
<?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 populateLookup(array $sets): array { $lookup = []; foreach ($sets as $id => $haystacks) { foreach ($haystacks as $haystack) { $lookup += array_fill_keys($haystack, $id); } } return $lookup; } $map = populateLookup($sales_people); var_export($map); echo "\n---\n"; var_export($map['CT'] ?? null);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
array ( 'NY' => 2, 'NJ' => 2, 'CT' => 2, 'MA' => 2, 'VT' => 2, 'ME' => 2, 'CA1' => 2, 'US7' => 2, 'UT9' => 2, 'FL' => 5, 'GA' => 5, 'SC' => 5, 'NC' => 5, 'TN' => 5, 'VA4' => 5, 'VA8' => 5, 'VA3' => 5, ) --- 2

preferences:
69.78 ms | 402 KiB | 62 Q