2

I have one array data output coming below format. i want to add total adults count with in the array.My out is below please find.

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
        )

)

Here in array object adults is total 1+2 =3 and childs is total 2+1=3. i tried below code not working

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

can any one please check and tell me where is the mistake in this code. i tried so many times not working below code.

1
  • Your attempt isn't adding anything up, it's just echoing out the values. Commented Jan 20, 2019 at 7:52

1 Answer 1

3

Try something like this:

$adult_count = 0;
$child_count = 0;

foreach($room_details as $count){
    $adult_count += $count->adults;
    $child_count += $count->childs;
}

echo $adult_count;
echo $child_count;
Sign up to request clarification or add additional context in comments.

2 Comments

I know you took that part from the question, but calling each row $adultcount is super confusing. I'd suggest the OP to change it.
Variable name is fixed now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.