php Remove parent level array from set of arrays and merge nodes

后端 未结 6 1056
执念已碎
执念已碎 2020-12-14 09:40

I am terrible with manipulating arrays...given this structure I want to remove the top level array and merge all subsets into one flat array:

Array
(
    [0]         


        
6条回答
  •  攒了一身酷
    2020-12-14 10:11

    If the values are always at the same level of depth you could indeed use array_merge:

    $array = [                                                                                                                                                                                                                                 
        [
            ['hey.com'],
            ['you.com'],
        ],                                                                                                                                                                                                                
        [
            ['this.com'],
            ['rocks.com'],
        ],                                                                                                                                                                                                             
    ];
    
    print_r(array_merge(... array_merge(... $array)));
    
    Getting:
    
    Array
    (
        [0] => hey.com
        [1] => you.com
        [2] => this.com
        [3] => rocks.com
    )
    

提交回复
热议问题