Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I combine two arrays of SimpleXML elements?
    primarykey
    data
    text
    <p>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?</p> <pre><code>Array ( [0] =&gt; SimpleXMLElement Object ( [companyLocationInfo] =&gt; Array ( [0] =&gt; SimpleXMLElement Object ( [companyName] =&gt; AVIS [name] =&gt; NYCC07 [line1] =&gt; 420 EAST 90TH STREET ) [2] =&gt; SimpleXMLElement Object ( [companyName] =&gt; AVIS [name] =&gt; NYCC06 [line1] =&gt; 310 EAST 64TH STREET ) [3] =&gt; SimpleXMLElement Object ( [companyName] =&gt; AVIS [name] =&gt; NYCC01 [line1] =&gt; 68 EAST 11TH STREET ) ) [rates] =&gt; Array ( [0] =&gt; SimpleXMLElement Object ( [companyName] =&gt; AVIS [name] =&gt; NYCC07 [vehicleRentalPrefType] =&gt; CCAR [rateAmount] =&gt; 83.99 [rateCurrency] =&gt; USD ) [2] =&gt; SimpleXMLElement Object ( [companyName] =&gt; AVIS [name] =&gt; NYCC06 [vehicleRentalPrefType] =&gt; CCAR [rateAmount] =&gt; 110.54 [rateCurrency] =&gt; USD ) [3] =&gt; SimpleXMLElement Object ( [companyName] =&gt; AVIS [name] =&gt; NYCC01 [vehicleRentalPrefType] =&gt; CCAR [rateAmount] =&gt; 210.65 [rateCurrency] =&gt; USD ) ) ) ) </code></pre> <p>I would like to combine them like this:</p> <pre><code>AVIS 420 EAST 90TH STREET CCAR 83.99 USD AVIS 310 EAST 64TH STREET CCAR 110.54 USD AVIS 68 EAST 11TH STREET CCAR 210.65 USD </code></pre> <p>With PHP how can I combine it like this?</p> <hr> <p>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, </p> <p>Here is an example below,</p> <pre><code>Array ( [0] =&gt; SimpleXMLElement Object ( [companyLocationInfo] =&gt; Array ( [0] =&gt; SimpleXMLElement Object ( [companyName] =&gt; AVIS [name] =&gt; NYCC07 [line1] =&gt; 420 EAST 90TH STREET ) [2] =&gt; SimpleXMLElement Object ( [companyName] =&gt; AVIS [name] =&gt; NYCC06 [line1] =&gt; 310 EAST 64TH STREET ) [3] =&gt; SimpleXMLElement Object ( [companyName] =&gt; AVIS [name] =&gt; NYCC01 [line1] =&gt; 68 EAST 11TH STREET ) ) [rates] =&gt; Array ( [0] =&gt; SimpleXMLElement Object ( [pickupDropoffLocations] =&gt; Array ( [0] =&gt; SimpleXMLElement Object ( [companyName] =&gt; AVIS [name] =&gt; NYCC07 ) ) [vehicleRentalPrefType] =&gt; CCAR [rateAmount] =&gt; 83.99 [rateCurrency] =&gt; USD ) [2] =&gt; SimpleXMLElement Object ( [pickupDropoffLocations] =&gt; Array ( [0] =&gt; SimpleXMLElement Object ( [companyName] =&gt; AVIS [name] =&gt; NYCC06 ) ) [vehicleRentalPrefType] =&gt; CCAR [rateAmount] =&gt; 110.54 [rateCurrency] =&gt; USD ) [3] =&gt; SimpleXMLElement Object ( [pickupDropoffLocations] =&gt; Array ( [0] =&gt; SimpleXMLElement Object ( [companyName] =&gt; AVIS [name] =&gt; NYCC01 ) ) [vehicleRentalPrefType] =&gt; CCAR [rateAmount] =&gt; 210.65 [rateCurrency] =&gt; USD ) ) ) ) </code></pre> <p>And this is the code what I'm using, but not working,</p> <pre><code>$results_array = array(); foreach($result[0]-&gt;rates as $rate) { foreach($result[0]-&gt;companyLocationInfo as $info) { if($info-&gt;name == $rate-&gt;pickupDropoffLocations[0]-&gt;name) { $results_array[] = array( 'line1' =&gt; $info-&gt;line1, 'name' =&gt; $info-&gt;locationDetails-&gt;name, 'companyName' =&gt; $info-&gt;companyName, 'vehicleRentalPrefType' =&gt; $rate-&gt;vehicleRentalPrefType ); } } } print_r($results_array); </code></pre> <p>And I want it should looks like:</p> <pre><code>AVIS 420 EAST 90TH STREET CCAR 83.99 USD AVIS 310 EAST 64TH STREET CCAR 110.54 USD AVIS 68 EAST 11TH STREET CCAR 210.65 USD </code></pre> <p>Can someone tell the problem of that code?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload