This paper illustrates a simple way to realize the one-dimensional array of PHP multidimensional arrays. Share to everyone for your reference, specific as follows:
The PHP language itself does not convert multidimensional arrays into one-dimensional arrays, but we can write a PHP function of our own to achieve the function of turning multidimensional into one dimension.
The use of recursion, simple and rough, the entire function body 9 lines of code to achieve this function, PHP source code is as follows:
$multi = Array (Array (
' wo ',
' Shi '
),
' php '
),
' Cheng ',
Array (
Array (
' Xu ',
' yuan ',
)
),
'! '
);
$multi = Arrtoone ($multi);
Print_r ($multi);
function Arrtoone ($multi) {
$arr = array ();
foreach ($multi as $key => $val) {
if (Is_array ($val)) {
$arr = Array_merge ($arr, Arrtoone ($val));
SE {
$arr [] = $val;
}
}
return $arr;
}
Effect after execution:
Array
(
[0] => wo
[1] => shi
[2] => PHP
[3] => Cheng
[4] => Xu
[5] => ; Yuan
[6] =>!
)
I hope this article will help you with the PHP program design.