This article mainly shares with you the method of converting PHP two-dimensional array into one-dimensional array. It is mainly shared with you in the form of code. I hope it can help you.
$arr = [ 'a' => [ 1, 2, ], 'b' => [ '3', '4'=>[ '5' ] ], 'b' ];
print_r(iterator_to_array( new RecursiveIteratorIterator( new RecursiveArrayIterator($arr) ), false ) );
Result:
Array ([0] => 1 [1] => 2 [2] => 3 [3] => 5 [4 ] => b )
Related recommendations:
php Convert a two-dimensional array into an array with a parent-child relationship_PHP tutorial
The above is the detailed content of How to convert two-dimensional array to one-dimensional array in PHP. For more information, please follow other related articles on the PHP Chinese website!