我看不出这段代码哪里错了,所以我请你帮忙。我有两个数组:
Array (
[0] => Array (
[description] => Generali di Proprieta'
[idmov] => 34
[mov] => Manutenzioni
[total] => 8000
)
[1] => Array (
[description] => Generali di Proprieta'
[idmov] => 35
[mov] => Assicurazioni
[total] => 6000
)
[2] => Array (
[description] => Generali di Proprieta'
[idmov] => 36
[mov] => Cancelleria Postali
[total] => 1850
)
[3] => Array (
[description] => Generali di Proprieta'
[idmov] => 37
[mov] => Bancarie passive
[total] => 700
)
[4] => Array (
[description] => Generali di Proprieta'
[idmov] => 38
[mov] => Amministrazione
[total] => 15000
)
)
和
Array (
[0] => Array (
[center] => 8
[caus] => 34
[total] => 38175.04
)
[1] => Array (
[center] => 8
[caus] => 35
[total] => 6132.00
)
[2] => Array (
[center] => 8
[caus] => 36
[total] => 223.80
)
[3] => Array (
[center] => 8
[caus] => 37
[total] => 114.70
)
[4] => Array (
[center] => 8
[caus] => 38
[total] => 14625.07
)
[5] => Array (
[center] => 8
[caus] => 39
[total] => 7450.48
)
我用这个功能
function searchForId($id, $array) {
foreach ($array as $key => $val) {
if ($val['caus'] === $id) {
return $key;
}
}
return null;
}
使用以下代码在数组 B 中查找数组 A 的每个项目:
for($i=0;$i<$length;$i++){
if(searchForId($voce_bdg[$i]['idmov'], $voce_actual)){
$key=searchForId($voce_bdg[$i]['idmov'], $voce_actual);
$actual=$voce_actual[$key]['importo'];
echo '<td class="report">'.number_format($actual,2,',','.').'</td>';
}else{
echo '<td class="report">0,00</td>';
}
}
它适用于每个项目,就像一个魅力,除了它返回 0 的第一个项目。
我哪里错了??
在此先感谢您的帮助!莱利奥