我有一个类似的数组,如下所示:
$agents = [
(object)["id"=> 301,"name"=> "Agent 1"],
(object)["id"=> 303,"name"=> "Agent 2"],
(object)["id"=> 301,"name"=> "Agent 3"],
(object)["id"=> 305,"name"=> "Agent 4"],
(object)["id"=> 306,"name"=> "Agent 5"],
(object)["id"=> 303,"name"=> "Agent 6"]
];
$locations = [
(object)["xid"=> 148,"location_name"=> "USA"],
(object)["xid"=> 149,"location_name"=> "CHINA"],
(object)["xid"=> 153,"location_name"=> "GERMANY"],
(object)["xid"=> 156,"location_name"=> "CANADA"],
(object)["xid"=> 167,"location_name"=> "SINGAPORE"],
(object)["xid"=> 0,"location_name"=> "No Location"]
];
$records = [
(object)["agent_id"=> 301,"location_id"=> 156,"total"=> 10000],
(object)["agent_id"=> 303,"location_id"=> 149,"total"=> 13000],
(object)["agent_id"=> 301,"location_id"=> 156,"total"=> 10000],
(object)["agent_id"=> 305,"location_id"=> 0,"total"=> 10000],
(object)["agent_id"=> 306,"location_id"=> 148,"total"=> 10000],
(object)["agent_id"=> 303,"location_id"=> 0,"total"=> 10000]
];
我正在try 将正确的事务分配到$AGENT-&>LOCATIONS->;事务中,但我的循环不起作用.
foreach ($agents as $a) {
foreach ($locations as $l) {
$a->locations[]=$l;
foreach ($records as $r) {
if($r->location_id == $l->xid && $r->agent_id == $a->id){
$l->transactions[] = $r;
}
}
}
}
这就是结果
我想要实现的是,事务应该在正确的代理下分配/过滤.请帮帮我..我已经关注这个循环太久了,不知道如何实现我需要的:(.