带有ifelse、foreach和in_数组的Php函数
瞄准。多次(在多个位置)需要检查数组键的值,并且基于带有ifelse、foreach和in_数组的Php函数,php,arrays,function,foreach,Php,Arrays,Function,Foreach,瞄准。多次(在多个位置)需要检查数组键的值,并且基于foreach中的值需要回显货币代码 将数组(例如)命名为$data\u pvn\u 1\u ii\u每个\u发票\u借方 Array ( [0] => Array ( [VatCodeCountryCode] => IE [VatCode] =>123456 ) [1] => Array ( [VatCodeCountryCode] => GB [VatCode] =>958725 ) ) 这里定义
foreach
中的值需要回显货币代码
将数组(例如)命名为$data\u pvn\u 1\u ii\u每个\u发票\u借方
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]);
}
然后是函数(函数的一部分)
然后需要回显货币代码(也只是代码的一部分)
其他运输署的内容
第一个问题:代码不能与一起使用(在数组中($trim\u result\u vat\u country\u code),$country\u codes\u with\u euro\u currency))
第二个问题:
echo myTest($trim\u result\u vat\u country\u code)代码>仅返回最后一个结果。对于数组键vatcodecontrycode
有IE
和GB
值。因此,需要回显货币EUR
和GBP
。但是只回显GBP第一个问题:
if( in_array($trim_result_vat_country_code), $country_codes_with_euro_currency))
<?php foreach($data_pvn_1_ii_each_invoice_debit as $i => $result){?>
<tr><td>
<?php echo myTest($result['VatCodeCountryCode']); ?>
</td></tr>
<tr><td>content of other td</td></tr>
<?php }?>
应该是
if( in_array($trim_result_vat_country_code, $country_codes_with_euro_currency))
在In_array
函数中,第二个参数应该是数组
第二个问题:
foreach($data_pvn_1_ii_each_invoice_debit as $i => $result){
$trim_result_vat_country_code = trim($result[VatCodeCountryCode]);
}
上面的代码只保存最后一条记录。这就是为什么myTest
函数只返回最后一条记录的原因
解决方案:
if( in_array($trim_result_vat_country_code), $country_codes_with_euro_currency))
<?php foreach($data_pvn_1_ii_each_invoice_debit as $i => $result){?>
<tr><td>
<?php echo myTest($result['VatCodeCountryCode']); ?>
</td></tr>
<tr><td>content of other td</td></tr>
<?php }?>
第一个问题:
if( in_array($trim_result_vat_country_code), $country_codes_with_euro_currency))
<?php foreach($data_pvn_1_ii_each_invoice_debit as $i => $result){?>
<tr><td>
<?php echo myTest($result['VatCodeCountryCode']); ?>
</td></tr>
<tr><td>content of other td</td></tr>
<?php }?>
应该是
if( in_array($trim_result_vat_country_code, $country_codes_with_euro_currency))
在In_array
函数中,第二个参数应该是数组
第二个问题:
foreach($data_pvn_1_ii_each_invoice_debit as $i => $result){
$trim_result_vat_country_code = trim($result[VatCodeCountryCode]);
}
上面的代码只保存最后一条记录。这就是为什么myTest
函数只返回最后一条记录的原因
解决方案:
if( in_array($trim_result_vat_country_code), $country_codes_with_euro_currency))
<?php foreach($data_pvn_1_ii_each_invoice_debit as $i => $result){?>
<tr><td>
<?php echo myTest($result['VatCodeCountryCode']); ?>
</td></tr>
<tr><td>content of other td</td></tr>
<?php }?>