简体   繁体   中英

how to merge two associative arrays with different keys

i have two arrays which i have decoded from json object. 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&currencyCode=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. so please help me out. thanks in advance.

you are looking for the function array_merge() ..You can do like this

<?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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM