Convert multidimensional array into single array

2018-12-31 20:43发布

I have an array which is multidimensional for no reason

/* This is how my array is currently */
Array
(
[0] => Array
    (
        [0] => Array
            (
                [plan] => basic
            )

        [1] => Array
            (
                [plan] => small
            )

        [2] => Array
            (
                [plan] => novice
            )

        [3] => Array
            (
                [plan] => professional
            )

        [4] => Array
            (
                [plan] => master
            )

        [5] => Array
            (
                [plan] => promo
            )

        [6] => Array
            (
                [plan] => newplan
            )

    )

 )

I want to convert this array into this form

/*Now, I want to simply it down to this*/
Array (
[0] => basic
[1] => small
[2] => novice
[3] => professional
[4] => master
[5] => promo
[6] => newplan
)

Any idea how to do this?

标签: php arrays
13条回答
旧时光的记忆
2楼-- · 2018-12-31 21:22
$flattenArray = [];

foreach ($parentArray as $childArray) {
    foreach ($childArray as $value) {
        $flattenArray[] = $value;
    }
}
查看更多
登录 后发表回答