[英]how to merge two associative arrays with different keys
i have two arrays which i have decoded from json object. 我有两个数组,我已经从json对象解码。 i need to merge both of them into one array. 我需要将它们都合并为一个数组。 to create a single array containg all key value. 创建包含所有键值的单个数组。
first array looks like - 第一个数组看起来像-
Array
(
[HotelListResponse] => Array
(
[customerSessionId] => 0ABAAACE-195B-3203-9142-76C8B9F63986
[numberOfRoomsRequested] => 1
[moreResultsAvailable] => 1
[cacheKey] => 195b3203:1476c8b9f63:8b
[cacheLocation] => 10.186.170.206:7300
[cachedSupplierResponse] => Array
(
[@supplierCacheTolerance] => NOT_SUPPORTED
[@cachedTime] => 0
[@supplierRequestNum] => 216
[@supplierResponseNum] => 20
[@supplierResponseTime] => 404
[@candidatePreptime] => 39
[@otherOverheadTime] => 26
[@tpidUsed] => 5202
[@matchedCurrency] => true
[@matchedLocale] => true
)
[HotelList] => Array
(
[@size] => 20
[@activePropertyCount] => 237
[HotelSummary] => Array
(
[0] => Array
(
[@order] => 0
[@ubsScore] => 4336013
[hotelId] => 214631
[name] => Chateau Windsor Hotel
[address1] => 86, Veer Nariman Road
[address2] => Next to Ambassador Hotel
[city] => Mumbai
[postalCode] => 400020
[countryCode] => IN
[airportCode] => BOM
[supplierType] => E
[propertyCategory] => 1
[hotelRating] => 3
[confidenceRating] => 52
[amenityMask] => 32768
[tripAdvisorRating] => 4
[tripAdvisorReviewCount] => 301
[tripAdvisorRatingUrl] => http://www.tripadvisor.com/img/cdsi/img2/ratings/traveler/4.0-12345-4.gif
[locationDescription] => Near Rajabai Tower
[shortDescription] => <p><b>Property Location</b> <br />With a stay at Chateau Windsor Hotel, you'll be centrally located in Mumbai, steps from Brabourne Stadium and minutes from Eros Theater. This hotel is close to
[highRate] => 5000
[lowRate] => 4250
[rateCurrencyCode] => INR
[latitude] => 18.9334
[longitude] => 72.82512
[proximityDistance] => 5.430785
[proximityUnit] => MI
[hotelInDestination] => 1
[thumbNailUrl] => /hotels/1000000/900000/893600/893528/893528_5_t.jpg
[deepLink] => http://travel.ian.com/index.jsp?pageName=hotAvail&cid=55505&hotelID=214631&mode=2&numberOfRooms=1&room-0-adult-total=2&room-0-child-total=0&arrivalMonth=6&arrivalDay=25&departureMonth=6&departureDay=28&showInfo=true&locale=en_US¤cyCode=INR
[RoomRateDetailsList] => Array
(
[RoomRateDetails] => Array
(
[roomTypeCode] => 200099868
[rateCode] => 200591602
[maxRoomOccupancy] => 4
[quotedRoomOccupancy] => 2
[minGuestAge] => 0
[roomDescription] => Superior Room
[propertyAvailable] => 1
[propertyRestricted] =>
[expediaPropertyId] => 893528
[RateInfos] => Array
(
[@size] => 1
[RateInfo] => Array
(
[@priceBreakdown] => true
[@promo] => true
[@rateChange] => false
[RoomGroup] => Array
(
[Room] => Array
(
[numberOfAdults] => 2
[numberOfChildren] => 0
)
)
[ChargeableRateInfo] => Array
(
[@averageBaseRate] => 5000.0
[@averageRate] => 4250.0
[@commissionableUsdTotal] => 212.13
[@currencyCode] => INR
[@maxNightlyRate] => 4250.0
[@nightlyRateTotal] => 12750.0
[@surchargeTotal] => 2221.05
[@total] => 14971.05
[NightlyRatesPerRoom] => Array
(
[@size] => 3
[NightlyRate] => Array
(
[0] => Array
(
[@baseRate] => 5000.0
[@rate] => 4250.0
[@promo] => true
)
[1] => Array
(
[@baseRate] => 5000.0
[@rate] => 4250.0
[@promo] => true
)
[2] => Array
(
[@baseRate] => 5000.0
[@rate] => 4250.0
[@promo] => true
)
)
)
[Surcharges] => Array
(
[@size] => 1
[Surcharge] => Array
(
[@type] => TaxAndServiceFee
[@amount] => 2221.05
)
)
)
[nonRefundable] => 1
[rateType] => MerchantStandard
[promoId] => 205317948
[promoDescription] => Sale! Save 15% on this Stay.
[promoType] => Standard
[currentAllotment] => 8
)
)
[ValueAdds] => Array
(
[@size] => 1
[ValueAdd] => Array
(
[@id] => 2
[description] => Continental Breakfast
)
)
)
)
)
)
)
)
) )
and this array 和这个数组
Array
(
[ResponseReferenceKey] => uCa3gAcgZY4eG04o38HGDg==
[HotelSearchResults] => Array
(
[Hotels] => Array
(
[0] => Array
(
[idContext] =>
[LowestRate] => Array
(
[LowestRate] => Array
(
[taxes] =>
[value] => 5700
[CurrencyCode] => INR
)
[DiscountedLowestRate] => Array
(
[taxes] =>
[value] => 5700
[CurrencyCode] => INR
)
)
[chainCode] =>
[nameCode] =>
[IsMysteryHotel] =>
[Name] => The Orchid
[id] => 20070418200017894
[PropertyInfo] => Array
(
[Facets] => Array
(
[0] => Array
(
[FacetValue] => Array
(
[value] => 5
[id] =>
[count] =>
)
[group] => STAR_RATING
)
[1] => Array
(
[FacetValue] => Array
(
[value] =>
[id] =>
[count] =>
)
[group] => CHAIN
)
[2] => Array
(
[FacetValues] => Array
(
[0] => Array
(
[value] => Gym
[id] =>
[count] =>
)
)
[group] => AMENITIES
)
)
[GuestRecommendations] => Array
(
[OverallRecommendation] => Array
(
[recommended] => 1
[DateTime] => 2014-03-03
[Rating] => Array
(
[maxRating] => 5
[value] => 5
)
[Comment] => Beautiful 5-star hotel. Awesome breakfast buffet (The best!!!)
[UserName] => Daniel Block
)
[IndividualGuestRecommendations] => Array
(
[0] => Array
(
[recommended] => 1
[DateTime] => 2014-03-03
[Rating] => Array
(
[maxRating] => 5
[value] => 5
)
[Comment] => Beautiful 5-star hotel. Awesome breakfast buffet (The best!!!)
[UserName] => Daniel Block
)
)
[totalRecommendations] => 61
)
[RoomStays] => Array
(
[0] => Array
(
[RoomTypes] => Array
(
[0] => Array
(
[bedTypeCode] =>
[nonSmoking] =>
[code] => 3
[name] => Deluxe
)
)
[RatePlans] => Array
(
[0] => Array
(
[code] => 94882176967240
[bundledTariff] =>
[MealPlans] => Array
(
[0] => Array
(
[code] => EP
[start] => 2014-08-03
[end] => 2014-08-05
[value] => Room Only
)
)
[Inclusions] => Array
(
[0] => Array
(
[code] => Two Way Airport Transfer
[start] => 2014-08-03
[end] => 2014-08-05
[value] => Two Way Airport Transfer
)
)
[name] => 94882176967240
[type] => OFFLINE
)
)
[RoomRates] => Array
(
[0] => Array
(
[inclusionAndPolicyAvail] => 1
[availableCount] => 25
[availStatus] => B
[Rate] => Array
(
[CancelPenalties] => Array
(
[0] => Array
(
[PenaltyDescription] => Array
(
[name] =>
[value] => More than 2 days before check-in date: FREE CANCELLATION. 2 days before check-in date: 1 night cost will be charged as cancellation fee. In case of no show: no refund. An additional MakeMyTrip service charge of INR 250 will apply
)
[type] =>
)
)
[RoomTariffs] => Array
(
[0] => Array
(
[Tariffs] => Array
(
[0] => Array
(
[amount] => 11400
[amountBeforeTax] =>
[amountAfterTax] =>
[type] => ROOM_RENT
[group] => ROOM_RATE
[currencyCode] => INR
)
)
[ExtraBedsIncluded] =>
[roomNumber] => 1
)
)
[PromotionReferences] => Array
(
)
)
[roomTypeCode] => 3
[ratePlanCode] => 94882176967240
)
)
[availStatus] => B
[startDate] => 2014-08-03
[endDate] => 2014-08-05
)
)
[Promotions] => Array
(
[0] => Array
(
[promotionName] =>
[code] => 39159894181198221
[TNCLink] =>
[promoLevel] => TARIFF_LEVEL_PROMO
[priceSlasher] => 1
[startDate] =>
[endDate] =>
[promoType] => PROMO_TYPE_DEAL
[value] => STAY MORE SAVE MORE !!!
)
)
[MediaList] => Array
(
[0] => Array
(
[main] => 1
[RoomCode] =>
[type] => IMAGE
[src] => http://images1.makemytrip.com/mmtimgs/images/upload/TheOrchid_Facade_Listing.jpg
)
)
)
)
[POS] => Array
(
[Requestor] => Array
(
[idContext] => AFF
[sourceId] =>
[id] => AFF304443
[type] => AFF
[channel] => AFF
)
[Source] => Array
(
[iSOCurrency] => INR
)
)
[AllHotels] => 1
[ResponseCode] => Array
(
[success] => 1
)
)
and i am doing it in php. 而我正在用PHP。 so please help me out. 所以请帮帮我 thanks in advance. 提前致谢。
you are looking for the function array_merge()
..You can do like this 您正在寻找功能array_merge()
..您可以这样做
<?php
$a1=array(); //add ur elements into the array
$a2=array();
print_r(array_merge($a1,$a2));
Then you are looking for this code: 然后,您正在寻找以下代码:
$result = array($array1, $array2);
print_r($result);
You have confused us with merging as merging always means to create one thing from two or more things. 您已将我们与合并混淆了,因为合并始终意味着从两个或多个事物中创建一个事物。 For the future it is always best if you could also provide us with how should the result look like... It is not necessary to insert such huge amount of data as well. 对于将来,最好还是向我们提供结果的样子……最好也不必插入如此大量的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.