Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有ifelse、foreach和in_数组的Php函数_Php_Arrays_Function_Foreach - Fatal编程技术网

带有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 }?>