How can I combine two arrays of SimpleXML elements?

h4ckz0r

New Member
The first array is the location and the second is the cars with their associated prices. How can I combine them like the sample below?\[code\]Array( [0] => SimpleXMLElement Object ( [companyLocationInfo] => Array ( [0] => SimpleXMLElement Object ( [companyName] => AVIS [name] => NYCC07 [line1] => 420 EAST 90TH STREET ) [2] => SimpleXMLElement Object ( [companyName] => AVIS [name] => NYCC06 [line1] => 310 EAST 64TH STREET ) [3] => SimpleXMLElement Object ( [companyName] => AVIS [name] => NYCC01 [line1] => 68 EAST 11TH STREET ) ) [rates] => Array ( [0] => SimpleXMLElement Object ( [companyName] => AVIS [name] => NYCC07 [vehicleRentalPrefType] => CCAR [rateAmount] => 83.99 [rateCurrency] => USD ) [2] => SimpleXMLElement Object ( [companyName] => AVIS [name] => NYCC06 [vehicleRentalPrefType] => CCAR [rateAmount] => 110.54 [rateCurrency] => USD ) [3] => SimpleXMLElement Object ( [companyName] => AVIS [name] => NYCC01 [vehicleRentalPrefType] => CCAR [rateAmount] => 210.65 [rateCurrency] => USD ) ) ))\[/code\]I would like to combine them like this:\[code\]AVIS 420 EAST 90TH STREETCCAR 83.99 USDAVIS 310 EAST 64TH STREETCCAR 110.54 USDAVIS 68 EAST 11TH STREETCCAR 210.65 USD\[/code\]With PHP how can I combine it like this?I just got an answer on my question but I can't get it work correctly, I want to combine to arrays, the first is the locations and the second is the cars, but in the second one is there another array which I have to match the values to the first array, Here is an example below,\[code\]Array( [0] => SimpleXMLElement Object ( [companyLocationInfo] => Array ( [0] => SimpleXMLElement Object ( [companyName] => AVIS [name] => NYCC07 [line1] => 420 EAST 90TH STREET ) [2] => SimpleXMLElement Object ( [companyName] => AVIS [name] => NYCC06 [line1] => 310 EAST 64TH STREET ) [3] => SimpleXMLElement Object ( [companyName] => AVIS [name] => NYCC01 [line1] => 68 EAST 11TH STREET ) ) [rates] => Array ( [0] => SimpleXMLElement Object ( [pickupDropoffLocations] => Array ( [0] => SimpleXMLElement Object ( [companyName] => AVIS [name] => NYCC07 ) ) [vehicleRentalPrefType] => CCAR [rateAmount] => 83.99 [rateCurrency] => USD ) [2] => SimpleXMLElement Object ( [pickupDropoffLocations] => Array ( [0] => SimpleXMLElement Object ( [companyName] => AVIS [name] => NYCC06 ) ) [vehicleRentalPrefType] => CCAR [rateAmount] => 110.54 [rateCurrency] => USD ) [3] => SimpleXMLElement Object ( [pickupDropoffLocations] => Array ( [0] => SimpleXMLElement Object ( [companyName] => AVIS [name] => NYCC01 ) ) [vehicleRentalPrefType] => CCAR [rateAmount] => 210.65 [rateCurrency] => USD ) ) ))\[/code\]And this is the code what I'm using, but not working,\[code\]$results_array = array();foreach($result[0]->rates as $rate) { foreach($result[0]->companyLocationInfo as $info) { if($info->name == $rate->pickupDropoffLocations[0]->name) { $results_array[] = array( 'line1' => $info->line1, 'name' => $info->locationDetails->name, 'companyName' => $info->companyName, 'vehicleRentalPrefType' => $rate->vehicleRentalPrefType ); } }}print_r($results_array);\[/code\]And I want it should looks like:\[code\]AVIS 420 EAST 90TH STREETCCAR 83.99 USDAVIS 310 EAST 64TH STREETCCAR 110.54 USDAVIS 68 EAST 11TH STREETCCAR 210.65 USD\[/code\]Can someone tell the problem of that code?
 
Back
Top