Page 1 of 1

[HELP] Get Current Array From Nested Array

Posted: Sun Dec 20, 2015 4:22 am
by Grandong
i have array like this :

Code: Select all

Array
(
    [depart] => Array
        (
            [0] => Array
                (
                    [segment] => Array
                        (
                            [0] => Array
                                (
                                    [4] => Array
                                        (
                                            [airline_code] => SJ
                                            [fno] => SJ598
                                            [class] => T
                                            [seat] => 8
                                            [from] => CGK
                                            [to] => TTE
                                            [std] => 00:05
                                            [sta] => 07:05
                                            [price] => 1,739,000
                                            [order_key] => 2137117:T:S:CGK:AMQ:U2s5VlVrNUZXUT09
                                        )

                                    [5] => Array
                                        (
                                            [airline_code] => SJ
                                            [fno] => SJ598
                                            [class] => Q
                                            [seat] => 9
                                            [from] => CGK
                                            [to] => TTE
                                            [std] => 00:05
                                            [sta] => 07:05
                                            [price] => 1,904,000
                                            [order_key] => 2137109:Q:S:CGK:AMQ:U2s5VlVrNUZXUT09
                                        )

                                )

                            [1] => Array
                                (
                                    [14] => Array
                                        (
                                            [airline_code] => SJ
                                            [fno] => SJ694
                                            [class] => Y
                                            [seat] => 9
                                            [from] => TTE
                                            [to] => AMQ
                                            [std] => 12:45
                                            [sta] => 13:35
                                            [price] => 1,224,000
                                            [order_key] => 1597216:Y:S:CGK:AMQ:U2s5VlVrNUZXUT09
                                        )

                                )

                        )

                )
hot to get frst array from [depart][key]['segment'][key2] then repair key to [0] ? like this :

Code: Select all

Array
(
    [depart] => Array
        (
            [0] => Array
                (
                    [segment] => Array
                        (
                            [0] => Array
                                (
                                    [0] => Array
                                        (
                                            [airline_code] => SJ
                                            [fno] => SJ598
                                            [class] => T
                                            [seat] => 8
                                            [from] => CGK
                                            [to] => TTE
                                            [std] => 00:05
                                            [sta] => 07:05
                                            [price] => 1,739,000
                                            [order_key] => 2137117:T:S:CGK:AMQ:U2s5VlVrNUZXUT09
                                        )

                                )

                            [1] => Array
                                (
                                    [0] => Array
                                        (
                                            [airline_code] => SJ
                                            [fno] => SJ694
                                            [class] => Y
                                            [seat] => 9
                                            [from] => TTE
                                            [to] => AMQ
                                            [std] => 12:45
                                            [sta] => 13:35
                                            [price] => 1,224,000
                                            [order_key] => 1597216:Y:S:CGK:AMQ:U2s5VlVrNUZXUT09
                                        )

                                )

                        )

                )
Please Help me...

Re: [HELP] Get Current Array From Nested Array

Posted: Sun Dec 20, 2015 12:16 pm
by Christopher
You need to foreach through $myarray['depart'][key]['segment'][key2] and copy the element to a new array. Use a counter variable that starts at zero and increments each assignment for the key to the new array.