[HELP] Get Current Array From Nested Array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Grandong
Forum Commoner
Posts: 65
Joined: Thu Jul 03, 2014 12:35 pm
Location: Indonesian
Contact:

[HELP] Get Current Array From Nested Array

Post 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...
Newbie The Passion for Learning
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: [HELP] Get Current Array From Nested Array

Post 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.
(#10850)
Post Reply