properly assign records into correct parent using foreach php
I have a similar arrays like below: $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"=>…