计算和添加数组php中的数组值

时间:2019-01-20 07:48:08

标签: php arrays

我有以下格式的一个数组数据输出。我想在数组中加上成人总数。请在下面找到我的答案。

Array
(
    [0] => stdClass Object
        (
            [id] => 4534
            [api] => expedia
            [AL_RefNo] => H190100000062
            [modify_refno] => H190100000062_1
            [Hotel_RefNo] => 325758353
            [Booking_RefNo] => 1234
            [affiliateConfirmationId] => OMEIR-1P3IWK2G8UXTIT5E2ELI2T2H1QI4H7
            [room_no] => 1
            [room_type] => Deluxe Double or Twin Room
            [arrivalDate] => 02/20/2019
            [departureDate] => 02/21/2019
            [nights] => 1
            [adults] => 1
            [childs] => 2
            [childs_ages] => 6,8
            [bedTypeId] => 
            [rateKey] => 26963a10-0e8d-41e0-ad55-478b8b2280fb
            [booking_status] => Confirmed
            [first_name] => hjgkjug
            [middle_name] => 
            [last_name] => jh
            [averageBaseRate] => 48.46
            [averageRate] => 48.46
            [commissionableUsdTotal] => 48.46
            [currency_val] => 1
            [Currency] => AED
            [Xml_Currency] => USD
            [eanCompensationOffline] => 0
            [eanCompensationOnline] => 0
            [maxNightlyRate] => 48.46
            [nightlyRateTotal] => 48.46
            [grossProfitOffline] => 0
            [grossProfitOnline] => 0
            [TotalBasePrice] => 61
            [TotalEqualBasePrice] => 
            [TotalEqualTax] => 
            [TotalTax] => 13
            [markup_type] => 
            [markup_percentage] => 
            [markup_amount] => 
            [markup_value_amount] => 0
            [markup_value_percentage] => 10.0000
            [extra_markup] => 0
            [extra_markup_percentage] => 0
            [markup_effective_to] => 2019-02-27
            [markup_per_night] => No
            [customer_markup] => 6.107
            [ota_discount_amount] => 0.00
            [ota_discount_type] => 
            [ota_discount_cal_amount] => 0.00
            [total] => 70.53585
            [dailyPrice] => 
            [surchargeTotal] => 12.61
            [NightlyRatesPerRoomsize] => 1
            [NightlyRatePromo] => false
            [baseRate] => 48.46
            [rate] => 48.46
            [surchargesSize] => 1
            [surchargeType] => TaxAndServiceFee
            [surchargeAmount] => 12.61
            [ratePlanType] => 
            [processedWithConfirmation] => true
            [booking_date] => 2019-01-17 15:01:01
            [remarks] => Refundable
            [room_type_code] => 
            [rateIdentifier] => 
            [status] => 
            [roomTotalPrice] => 
            [serviceDate] => 
            [dailypriceType] => 
            [mealBasisCodeDay] => 
            [mealIdDay] => 
            [mealTypeDay] => 
            [descriptionDay] => 
            [roomDescription] => 
            [roomCategory] => 
            [transactionID] => 
            [payment_charge] => 
            [room_code] => 
            [description] => 
            [commission] => 
            [gross_price] => 
            [nett_price] => 
            [Cancellation_Charge] => 
            [Cancel_Till_Date] => 
            [Cancelled_By] => 
            [rateClass] => 
            [rateComments] => 
            [paymentType] => 
            [packaging] => 
            [cancel_amount] => 
            [cancel_from_date] => 
            [actual_hotel_confirmation_number] => 
            [meal_type] => Free Wireless Internet|Free Breakfast
            [supplier_price] => 
            [sell_price] => 
            [client_price] => 
            [total_sell_price] => 
            [ota_booking_status] => 
            [Cancellation_Status] => 
            [Cancellation_Charge_Amount] => 
            [Cancelled_Markup] => 
            [Cancelled_Extra_Markup] => 
            [Refundable_Amont] => 
            [room_daily_rates] => [{"offset":1,"providerCost":48.46,"baseRate":48.46,"promo":"false","checkIn":"20-02-2019","totalTax":12.61,"inputVat":0,"markup":6.107,"eMarkup":0,"discount":"","outputVat":3.6642,"totalAmount":70.8412,"status":"A"}]
            [vat_effective_to] => 2050-02-01
            [vat_price] => 3.36
            [vat_percentage] => 5
            [input_vat_percentage] => 0
            [input_vat_price] => 0
            [cost_components] => ["Base Price","Markup"]
            [register_supplier] => Yes
            [inclusive_vat] => No
            [gcc_supplier] => 
            [price_rate_with_triple_plus] => 
            [hotel_service_percentage] => 
            [tourism_fee_percentage] => 
            [municipality_fee_percentage] => 
            [hotel_service_price] => 
            [tourism_fee_price] => 
            [municipality_fee_price] => 
            [direct_hotel_booking] => No
            [supplier_cancellation_charge] => 
            [vat_cancellation_charge] => 
            [modify_booking_status] => 
            [parent_modify_refno] => 
            [refundable_status] => Refundable
            [modify_status] => Yes
            [updated_on] => 2019-01-17 19:56:55
        )

    [1] => stdClass Object
        (
            [id] => 4535
            [api] => expedia
            [AL_RefNo] => H190100000062
            [modify_refno] => H190100000062_1
            [Hotel_RefNo] => 325758353
            [Booking_RefNo] => 1235
            [affiliateConfirmationId] => OMEIR-1P3IWK2G8UXTIT5E2ELI2T2H1QI4H7
            [room_no] => 2
            [room_type] => Deluxe Double or Twin Room
            [arrivalDate] => 02/20/2019
            [departureDate] => 02/21/2019
            [nights] => 1
            [adults] => 2
            [childs] => 1
            [childs_ages] => 10
            [bedTypeId] => 
            [rateKey] => 5baad87e-8d89-43fc-8553-357e885e7f0c
            [booking_status] => Confirmed
            [first_name] => hjgkjug
            [middle_name] => 
            [last_name] => jh
            [averageBaseRate] => 48.46
            [averageRate] => 48.46
            [commissionableUsdTotal] => 48.46
            [currency_val] => 1
            [Currency] => AED
            [Xml_Currency] => USD
            [eanCompensationOffline] => 0
            [eanCompensationOnline] => 0
            [maxNightlyRate] => 48.46
            [nightlyRateTotal] => 48.46
            [grossProfitOffline] => 0
            [grossProfitOnline] => 0
            [TotalBasePrice] => 61
            [TotalEqualBasePrice] => 
            [TotalEqualTax] => 
            [TotalTax] => 13
            [markup_type] => 
            [markup_percentage] => 
            [markup_amount] => 
            [markup_value_amount] => 0
            [markup_value_percentage] => 10.0000
            [extra_markup] => 0
            [extra_markup_percentage] => 0
            [markup_effective_to] => 2019-02-27
            [markup_per_night] => No
            [customer_markup] => 6.107
            [ota_discount_amount] => 0.00
            [ota_discount_type] => 
            [ota_discount_cal_amount] => 0.00
            [total] => 70.53585
            [dailyPrice] => 
            [surchargeTotal] => 12.61
            [NightlyRatesPerRoomsize] => 1
            [NightlyRatePromo] => false
            [baseRate] => 48.46
            [rate] => 48.46
            [surchargesSize] => 1
            [surchargeType] => TaxAndServiceFee
            [surchargeAmount] => 12.61
            [ratePlanType] => 
            [processedWithConfirmation] => true
            [booking_date] => 2019-01-17 15:01:01
            [remarks] => Refundable
            [room_type_code] => 
            [rateIdentifier] => 
            [status] => 
            [roomTotalPrice] => 
            [serviceDate] => 
            [dailypriceType] => 
            [mealBasisCodeDay] => 
            [mealIdDay] => 
            [mealTypeDay] => 
            [descriptionDay] => 
            [roomDescription] => 
            [roomCategory] => 
            [transactionID] => 
            [payment_charge] => 
            [room_code] => 
            [description] => 
            [commission] => 
            [gross_price] => 
            [nett_price] => 
            [Cancellation_Charge] => 
            [Cancel_Till_Date] => 
            [Cancelled_By] => 
            [rateClass] => 
            [rateComments] => 
            [paymentType] => 
            [packaging] => 
            [cancel_amount] => 
            [cancel_from_date] => 
            [actual_hotel_confirmation_number] => 
            [meal_type] => Free Wireless Internet|Free Breakfast
            [supplier_price] => 
            [sell_price] => 
            [client_price] => 
            [total_sell_price] => 
            [ota_booking_status] => 
            [Cancellation_Status] => 
            [Cancellation_Charge_Amount] => 
            [Cancelled_Markup] => 
            [Cancelled_Extra_Markup] => 
            [Refundable_Amont] => 
            [room_daily_rates] => [{"offset":1,"providerCost":48.46,"baseRate":48.46,"promo":"false","checkIn":"20-02-2019","totalTax":12.61,"inputVat":0,"markup":6.107,"eMarkup":0,"discount":"","outputVat":3.6642,"totalAmount":70.8412,"status":"A"}]
            [vat_effective_to] => 2050-02-01
            [vat_price] => 3.36
            [vat_percentage] => 5
            [input_vat_percentage] => 0
            [input_vat_price] => 0
            [cost_components] => ["Base Price","Markup"]
            [register_supplier] => Yes
            [inclusive_vat] => No
            [gcc_supplier] => 
            [price_rate_with_triple_plus] => 
            [hotel_service_percentage] => 
            [tourism_fee_percentage] => 
            [municipality_fee_percentage] => 
            [hotel_service_price] => 
            [tourism_fee_price] => 
            [municipality_fee_price] => 
            [direct_hotel_booking] => No
            [supplier_cancellation_charge] => 
            [vat_cancellation_charge] => 
            [modify_booking_status] => 
            [parent_modify_refno] => 
            [refundable_status] => Refundable
            [modify_status] => Yes
            [updated_on] => 2019-01-17 19:56:55
        )

)

在数组对象中,成人总计1 + 2 = 3,而孩子总计2 + 1 = 3。 我尝试了下面的代码不起作用

foreach($room_details as $adultcount){
            echo $adultcount->adults;
            echo $adultcount->childs;
        }

任何人都可以检查一下并告诉我此代码中的错误在哪里。我尝试了很多次都无法在代码下工作。

1 个答案:

答案 0 :(得分:3)

尝试这样的事情:

sox basefile.mp3 -r 16000 -c 1 newfile.flac
相关问题