php merge arrays

前端 未结 6 1657
北海茫月
北海茫月 2021-01-21 08:33

I have been trying (unsuccessfully) to merge the output of multiple arrays into a single array. An example of what I tried was:

$data1 = array(\"cat\", \"goat\")         


        
6条回答
  •  后悔当初
    2021-01-21 08:56

    There may be a better way, but this should work. Just loop through and merge each array individually:

    $items = array();
    
    foreach ($lines as $inner){
        $item = array($inner[1]);
    
        $items = array_merge($items, $item);
    }
    
    echo "
    ";
    print_r($items);
    echo "
    ";

提交回复
热议问题