我有两个这样的数组:$left = [ ['UserID' => 6835406], ['UserID' => 8418097],];$right = [ ['Amount' => 0.00, 'UserID' => 6835406], ['Amount' => 0.00, 'UserID' => 8418097]];我正在使用此函数对基于UserIDfeild的数组执行左连接:function left_join_array($left, $right, $left_join_on, $right_join_on = NULL){ $final= array(); if(empty($right_join_on)) $right_join_on = $left_join_on; foreach($left AS $k => $v){ $final[$k] = $v; foreach($right AS $kk => $vv){ if($v[$left_join_on] == $vv[$right_join_on]){ foreach($vv AS $key => $val) $final[$k][$key] = $val; } else { foreach($vv AS $key => $val) $final[$k][$key] = NULL; } } } return $final;}我这样调用函数:$out = $this->left_join_array($left,$right,'UserID','UserID');echo "<pre>";print_r($out);这是输出:Array( [0] => Array ( [UserID] => [Amount] => ) [1] => Array ( [UserID] => 8418097 [Amount] => 0.00 ))但所需的输出应该是这样的: Array ( [0] => Array ( [UserID] => 6835406 [Amount] => 0.00 ) [1] => Array ( [UserID] => 8418097 [Amount] => 0.00 ) )我的代码有什么问题?为什么它不提供所需的输出。任何的意见都将会有帮助。
1 回答
- 1 回答
- 0 关注
- 180 浏览
添加回答
举报
0/150
提交
取消