Created
August 13, 2016 18:57
-
-
Save kalimatas/d83d77d6b17758922755830f7bfca99b to your computer and use it in GitHub Desktop.
Nested array creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$taxes = [ | |
[ | |
'country_id' => 'a', | |
'value' => 42, | |
'type' => 't1', | |
], | |
[ | |
'country_id' => 'a', | |
'value' => 88, | |
'type' => 't2', | |
], | |
[ | |
'country_id' => 'b', | |
'value' => 10, | |
'type' => 't1', | |
], | |
]; | |
$countries = [ | |
[ | |
'id' => 'a', | |
'code' => 'a_code', | |
], | |
[ | |
'id' => 'b', | |
'code' => 'b_code', | |
], | |
[ | |
'id' => 'c', | |
'code' => 'c_code', | |
], | |
]; | |
$countryTaxMap = [ | |
'd_code' => [ | |
't4' => 8, | |
], | |
]; | |
foreach ($taxes as $tax) { | |
foreach ($countries as $country) { | |
if ($tax['country_id'] == $country['id']) { | |
$countryTaxMap[$country['code']][$tax['type']] = $tax['value']; | |
} | |
} | |
} | |
print_r($countryTaxMap); | |
echo PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment