最初の配列は場所で、2 番目の配列は車とそれに関連付けられた価格です。以下のサンプルのように組み合わせるにはどうすればよいですか?
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
)
)
)
)
以下のように組み合わせたいと思います。
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
PHPでは、どうすればこのように組み合わせることができますか?
質問に対する回答が得られましたが、正しく機能させることができません。配列に結合したいのですが、最初は場所で、2 番目は車ですが、2 番目には別の配列が必要です。値を最初の配列に一致させます。
以下に例を示します。
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
)
)
)
)
そして、これは私が使用しているコードですが、機能していません。
$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);
そして、私はそれが次のようになることを望みます:
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
誰かがそのコードの問題を教えてもらえますか?