如何在PHP中删除父数组

时间:2018-11-29 18:17:41

标签: php

我想删除group_id下面的父数字数组,并让收件人数组位于group_id之后。

 [1] => Array
    (
        [group_id] => 1234
        [0] => Array
            (
                [recipients] => Array
                    (
                        [0] => Array
                            (
                                [recipient_id] => 2
                                [name] => Another Tester
                                [email] => testertest@test.com
                                [phone] => 1230001234
                            )

                        [1] => Array
                            (
                                [recipient_id] => 10
                                [name] => teadsf
                                [email] => newguy@test.com
                                [phone] => 1230001234
                            )

1 个答案:

答案 0 :(得分:0)

一种方法是通过一些数组修改操作来for..each循环:

//$input is your original input array

// final output array
$output = array();

// Loop over the array
foreach ($input as $key => $value) {

    $output[$key]['group_id'] = $value['group_id'];

    // Set recipients key at the same level as group_id
    // Access the value at [0]['recipients']
    $output[$key]['recipients'] = $value[0]['recipients'];
}