douhong1703
2014-12-15 10:08
浏览 56
已采纳

从多维数组中删除数组键

Below is my array flightOne, a multidimensional array with two arrays as array elements [abc] and [efg]

    array( 'flightOne' => Array
    (
        'abc' => Array
            (
                '2014-12-15' => Array
                    (
                        2 => Array
                            (
                                'no' => 11,
                                'name' => 'Firstname Secondname', 
                                'dep_date' => '2014-12-15',
                                'flight' => 'flightOne',
                                'itinerary' => 'abc'
                            )

                    )

            ),

        'efg' => Array
            (
                '2014-12-15' => Array
                    (
                        5 => Array
                            (
                                'no' => 11,
                                'name' => 'Firstname Secondname', 
                                'dep_date' => '2014-12-15',
                                'flight' => 'flightOne',
                                'itinerary' => 'efg'
                            )

                    )

            )

    )

)

What i want is to remove the [efg] array key and combine with the [abc] key, so that the content of efg would be combined in the content of [abc] and give me something like.

array('flightOne' => Array
        (
            'abc' => Array
                (
                    '2014-12-15' => Array
                        (
                            2 => Array
                                (
                                    'no' => 11,
                                    'name' => 'Firstname Secondname', 
                                    'dep_date' => '2014-12-15',
                                    'flight' => 'flightOne',
                                    'itinerary' => 'abc'
                                ),
                            5 => Array
                                (
                                    'no' => 11,
                                    'name' => 'Firstname Secondname', 
                                    'dep_date' => '2014-12-15',
                                    'flight' => 'flightOne',
                                    'itinerary' => 'efg'
                                )   

                        )

                )
        )

)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douwen0647 2014-12-15 10:13
    已采纳
    $array['flightOne']['abc']['2014-12-15'] = 
        array_merge($array['flightOne']['abc']['2014-12-15'], 
                    $array['flightOne']['ghi']['2014-12-15']);
    unset($array['flightOne']['ghi']);
    
    点赞 打赏 评论

相关推荐 更多相似问题