static public function ppsp($date,$date2){
foreach($date as $y=> $v){
foreach($date2 as $u=> $f)
if($v['id'] == $f['fid']){
$date[$y]['child'][]=$date2[$u];
$af[] = $date[$y];
}
}
return $af;
}
这个函数在处理$date[$y]['child'][]=$date2[$u];时,因为外层循环了foreach($date2 as $u=> $f),
会出现新得到的数组和老数组重复叠加:
array{
[0]=>array{
'child'=>array{
[0]=>'第一条满足条件的$date2'
}
}
[1]=>array{
'child'=>array{
[0]=>'第一条满足条件的$date2'
[1]=>'第2条满足条件的$date2'
}
}
[2]=>array{
'child'=>array{
[0]=>'第一条满足条件的$date2'
[1]=>'第2条满足条件的$date2'
[2]=>'第3条满足条件的$date2'
}
}
}
--------------------------------------------------------------------------------
这里
[2]=>array{
'child'=>array{
[0]=>'第一条满足条件的$ngoods'
[1]=>'第2条满足条件的$ngoods'
[2]=>'第3条满足条件的$ngoods'
}
}
这条记录就是想要的结果,前两条是之前循环的,有没有办法只要最后这条,前两条不要
最佳答案