<?php $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] ]; foreach($agents as $agent){ $agent->locations = []; foreach($locations as $location){ $location = clone $location; $location->transactions = []; foreach($records as $r){ if($r->agent_id == $agent->id && $location->xid == $r->location_id){ $location->transactions[] = $r; } } $agent->locations[] = $location; } } print_r($agents);
You have javascript disabled. You will not be able to edit any code.
This script was stopped while abusing our resources