標的。複数回 (複数の場所で) 配列キーの値を確認する必要があり、内部の値に基づいてforeach
通貨コードをエコーする必要があります。
名前付きの配列を (例として) 持つ$data_pvn_1_ii_each_invoice_debit
Array (
[0] => Array ( [VatCodeCountryCode] => IE [VatCode] =>123456 )
[1] => Array ( [VatCodeCountryCode] => GB [VatCode] =>958725 )
)
ここでは、通貨がユーロである国の略語を含む変数を定義します。
$country_codes_with_euro_currency = array( 'AT', 'BE', 'CY', 'DE', 'EE', 'GR', 'ES', 'FI', 'FR', 'IE', 'IT', 'LU', 'MT', 'NL', 'PT', 'SI', 'SK' );
次に、複数回(複数の場所で)[VatCodeCountryCode]
国コードの値を確認し、それに基づいて通貨をエコーする必要があります
最初は取得しようとしています[VatCodeCountryCode]
。
foreach($data_pvn_1_ii_each_invoice_debit as $i => $result){
$trim_result_vat_country_code = trim($result[VatCodeCountryCode]);
}
次に機能(機能の一部)
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';
}
}
そして、通貨コードをエコーする必要があります(コードの一部のみ)
<?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 }?>
最初の問題: コードが動作しない( in_array($trim_result_vat_country_code), $country_codes_with_euro_currency) )
2 番目の問題:echo myTest($trim_result_vat_country_code);
最後の結果のみを返します。配列キーVatCodeCountryCode
には、値IE
とがありますGB
。EUR
したがって、通貨とをエコーする必要がありGBP
ます。ただし、エコーのみGBP