Page 1 of 1

[HELP] How to make array like this

Posted: Tue Dec 08, 2015 7:30 am
by Grandong
Hi...
i have array like :

Code: Select all

Array
(
    [arrivalAirport] => Array
        (
            [city] => DPS
            [cityCode] => 
            [code] => DPS
            [countryCode] => 
            [latitude] => -8.748169
            [longitude] => 115.167172
            [name] => Bali Ngurah Rai, Denpasar
            [timezone] => 
        )

    [departureAirport] => Array
        (
            [city] => CGK
            [cityCode] => 
            [code] => CGK
            [countryCode] => 
            [latitude] => -6.125567
            [longitude] => 106.655897
            [name] => Soekarno Hatta Intl, Jakarta
            [timezone] => 
        )

    [flightSegments] => Array
        (
            [0] => Array
                (
                    [aircraftCode] => 
                    [airline] => Array
                        (
                            [code] => QG
                            [name] => Citilink
                        )

                    [arrivalAirport] => Array
                        (
                            [city] => DPS
                            [cityCode] => 
                            [code] => DPS
                            [countryCode] => 
                            [latitude] => -8.748169
                            [longitude] => 115.167172
                            [name] => Bali Ngurah Rai, Denpasar
                            [timezone] => 
                        )

                    [departureAirport] => Array
                        (
                            [city] => CGK
                            [cityCode] => 
                            [code] => CGK
                            [countryCode] => 
                            [latitude] => -6.125567
                            [longitude] => 106.655897
                            [name] => Soekarno Hatta Intl, Jakarta
                            [timezone] => 
                        )

                    [duration] => 
                    [fares] => Array
                        (
                            [0] => Array
                                (
                                    [adminFee] => 0
                                    [airportTax] => 40000
                                    [availableCount] => 0
                                    [baggageAllowance] => 0
                                    [basicFare] => 935300
                                    [basicVat] => 93500
                                    [childFare] => 701500
                                    [childVat] => 70100
                                    [classOfService] => G
                                    [currency] => IDR
                                    [fareSellKey] => 0~G~~GG~PRFR~~1~X
                                    [fareType] => PR
                                    [fuelSurcharge] => 0
                                    [infantFare] => 200000
                                    [infantVat] => 20000
                                    [insurance] => 0
                                    [iwjr] => 5000
                                    [otherFee] => 0
                                    [serviceFee] => 0
                                )

                        )

                    [flightDesignator] => Array
                        (
                            [carrierCode] => QG
                            [flightNumber] => 9743
                        )

                    [includedBaggage] => 20
                    [includedMeal] => 0
                    [segmentSellKey] => QG~9743~ ~~CGK~12/11/2015 13:10~DPS~12/11/2015 15:55~
                    [selectedFare] => 
                    [sta] => 2015-12-11T15:55:00
                    [std] => 2015-12-11T13:10:00
                )

        )

    [journeySellKey] => QG~9743~ ~~CGK~12/11/2015 13:10~DPS~12/11/2015 15:55~
    [stopCount] => 0
)
how to make array at the top to like this:

Code: Select all

Array
(
    [arrivalAirport] => Array
        (
            [city] => DPS
            [cityCode] => 
            [code] => DPS
            [countryCode] => 
            [latitude] => -8.748169
            [longitude] => 115.167172
            [name] => Bali Ngurah Rai, Denpasar
            [timezone] => 
        )

    [departureAirport] => Array
        (
            [city] => CGK
            [cityCode] => 
            [code] => CGK
            [countryCode] => 
            [latitude] => -6.125567
            [longitude] => 106.655897
            [name] => Soekarno Hatta Intl, Jakarta
            [timezone] => 
        )

    [flightSegments] => Array
        (
            [0] => Array
                (
                    [aircraftCode] => 
                    [airline] => Array
                        (
                            [code] => QG
                            [name] => Citilink
                        )

                    [arrivalAirport] => Array
                        (
                            [city] => DPS
                            [cityCode] => 
                            [code] => DPS
                            [countryCode] => 
                            [latitude] => -8.748169
                            [longitude] => 115.167172
                            [name] => Bali Ngurah Rai, Denpasar
                            [timezone] => 
                        )

                    [departureAirport] => Array
                        (
                            [city] => CGK
                            [cityCode] => 
                            [code] => CGK
                            [countryCode] => 
                            [latitude] => -6.125567
                            [longitude] => 106.655897
                            [name] => Soekarno Hatta Intl, Jakarta
                            [timezone] => 
                        )

                    [duration] => 
                    [selectedFare] => Array
                        (
                                    [adminFee] => 0
                                    [airportTax] => 40000
                                    [availableCount] => 0
                                    [baggageAllowance] => 0
                                    [basicFare] => 935300
                                    [basicVat] => 93500
                                    [childFare] => 701500
                                    [childVat] => 70100
                                    [classOfService] => G
                                    [currency] => IDR
                                    [fareSellKey] => 0~G~~GG~PRFR~~1~X
                                    [fareType] => PR
                                    [fuelSurcharge] => 0
                                    [infantFare] => 200000
                                    [infantVat] => 20000
                                    [insurance] => 0
                                    [iwjr] => 5000
                                    [otherFee] => 0
                                    [serviceFee] => 0
                        )

                    [flightDesignator] => Array
                        (
                            [carrierCode] => QG
                            [flightNumber] => 9743
                        )

                    [includedBaggage] => 20
                    [includedMeal] => 0
                    [segmentSellKey] => QG~9743~ ~~CGK~12/11/2015 13:10~DPS~12/11/2015 15:55~
                    [fares] => 
                    [sta] => 2015-12-11T15:55:00
                    [std] => 2015-12-11T13:10:00
                )

        )

    [journeySellKey] => QG~9743~ ~~CGK~12/11/2015 13:10~DPS~12/11/2015 15:55~
    [stopCount] => 0
)
Condition:
- Change fares to selectedFare without [0]
thx...

Re: [HELP] How to make array like this

Posted: Wed Dec 09, 2015 11:30 am
by Grandong
Somebody Help me Please....

Re: [HELP] How to make array like this

Posted: Wed Dec 09, 2015 11:35 am
by Celauran
What if there is more than one item in fares?

Re: [HELP] How to make array like this

Posted: Wed Dec 09, 2015 11:46 am
by Grandong
Celauran wrote:What if there is more than one item in fares?
It will not happen, please give me example...

Re: [HELP] How to make array like this

Posted: Wed Dec 09, 2015 11:49 am
by Celauran
So then just iterate over your flight segments, set selectedFare to fares[0], and unset fares

Re: [HELP] How to make array like this

Posted: Wed Dec 09, 2015 11:54 am
by Grandong
Celauran wrote:So then just iterate over your flight segments, set selectedFare to fares[0], and unset fares
detail like this:
i will change :

Code: Select all

                    [fares] => Array
                        (
                            [0] => Array
                                (
                                    [adminFee] => 0
                                    [airportTax] => 40000
                                    [availableCount] => 0
                                    [baggageAllowance] => 0
                                    [basicFare] => 935300
                                    [basicVat] => 93500
                                    [childFare] => 701500
                                    [childVat] => 70100
                                    [classOfService] => G
                                    [currency] => IDR
                                    [fareSellKey] => 0~G~~GG~PRFR~~1~X
                                    [fareType] => PR
                                    [fuelSurcharge] => 0
                                    [infantFare] => 200000
                                    [infantVat] => 20000
                                    [insurance] => 0
                                    [iwjr] => 5000
                                    [otherFee] => 0
                                    [serviceFee] => 0
                                )

                        )
to

Code: Select all

[fares] =>
then set selectedFare

Code: Select all

                    [selectedFare] => Array
                        (
                                    [adminFee] => 0
                                    [airportTax] => 40000
                                    [availableCount] => 0
                                    [baggageAllowance] => 0
                                    [basicFare] => 935300
                                    [basicVat] => 93500
                                    [childFare] => 701500
                                    [childVat] => 70100
                                    [classOfService] => G
                                    [currency] => IDR
                                    [fareSellKey] => 0~G~~GG~PRFR~~1~X
                                    [fareType] => PR
                                    [fuelSurcharge] => 0
                                    [infantFare] => 200000
                                    [infantVat] => 20000
                                    [insurance] => 0
                                    [iwjr] => 5000
                                    [otherFee] => 0
                                    [serviceFee] => 0
                        )
Please, Give me example code....

Re: [HELP] How to make array like this

Posted: Wed Dec 09, 2015 11:57 am
by Celauran
I just explained how to do it. What have you tried and what isn't working?

Re: [HELP] How to make array like this

Posted: Wed Dec 09, 2015 12:00 pm
by Grandong
Celauran wrote:I just explained how to do it. What have you tried and what isn't working?
i try using array_map
but not working

Re: [HELP] How to make array like this

Posted: Wed Dec 09, 2015 12:29 pm
by Christopher
Something like?

Code: Select all

$selectedFares = array();
foreach ($fares as $fare) {
    $selectedFares[] = $fare;
}
Or as simple as:

Code: Select all

$selectedFare = $fares[0];