Aim. Multiple times (in multiple places) need to check value of array key and based on the value inside foreach
need to echo currency code.
Have array (as example), named $data_pvn_1_ii_each_invoice_debit
Array (
[0] => Array ( [VatCodeCountryCode] => IE [VatCode] =>123456 )
[1] => Array ( [VatCodeCountryCode] => GB [VatCode] =>958725 )
)
Here define variable which includes abbreviations of countries, where currency is euro.
$country_codes_with_euro_currency = array( 'AT', 'BE', 'CY', 'DE', 'EE', 'GR', 'ES', 'FI', 'FR', 'IE', 'IT', 'LU', 'MT', 'NL', 'PT', 'SI', 'SK' );
Then multiple times (in multiple places) need to check value of [VatCodeCountryCode]
and based on country code need to echo currency
At first trying to get [VatCodeCountryCode]
.
foreach($data_pvn_1_ii_each_invoice_debit as $i => $result){
$trim_result_vat_country_code = trim($result[VatCodeCountryCode]);
}
Then function (part of function)
function myTest($trim_result_vat_country_code) {
if ( in_array($trim_result_vat_country_code), $country_codes_with_euro_currency) ) {
return $currency_code = 'EUR';
}
elseif ( $trim_result_vat_country_code == 'GB' ) {
return $currency_code = 'GBP';
}
}
And then need to echo currency code (also only part of code)
<?php foreach($data_pvn_1_ii_each_invoice_debit as $i => $result){?>
<tr><td>
<?php echo myTest($trim_result_vat_country_code); ?>
</td></tr>
<tr><td>content of other td</td></tr>
<?php }?>
First problem: code does not work with ( in_array($trim_result_vat_country_code), $country_codes_with_euro_currency) )
Second problem: echo myTest($trim_result_vat_country_code);
returns only last result. For array key VatCodeCountryCode
there are values IE
and GB
. So need to echo currencies EUR
and GBP
. But echo only GBP