Home > Article > Backend Development > How to convert a two-dimensional array into a one-dimensional array in php
php How to convert a two-dimensional array into a one-dimensional array: first create a PHP sample file; then define a "reduce" method; then use "array_walk_recursive" and other functional methods to achieve the conversion.
Recommended: "PHP Video Tutorial"
php convert two-dimensional array to one-dimensional array
The code is as follows:
/* @reduce() 多维维数组变成一维数组 @$array 数组 */ public function reduce($array) { $return = []; array_walk_recursive($array, function ($x, $index) use (&$return) { $return[] = $x; }); return $return; }
The above is the detailed content of How to convert a two-dimensional array into a one-dimensional array in php. For more information, please follow other related articles on the PHP Chinese website!