Recursive function for converting a multi-dimensional array into a one-dimensional array
Source: Internet
Author: User
Use recursion to convert a multi-dimensional array into a one-dimensional array. Read the function that uses recursion to convert a multi-dimensional array into a one-dimensional array. function name: array_multi2single function prototype: arrayarray_multi2single (array) implementation function: store the value of a multi-dimensional array into a one-dimensional array without storing the Key .? Phpfunctionarray_multi2s function name: array_multi2single
Original function: array array_multi2single (array)
Function: store the values of a multi-dimensional array into a one-dimensional array without storing keys.
Function array_multi2single ($ array)
{
Static $ result_array = array ();
Foreach ($ array as $ value)
{
If (is_array ($ value ))
{
Array_multi2single ($ value );
}
Else
$ Result_array [] = $ value;
}
Return $ result_array;
}
// Function Testing
$ Array = array ("1" => array ("A", "B", "C", array ("D", "E ")), "2" => array ("F", "G", "H", "I "));
$ Array = array_multi2single ($ array );
Echo "test result :";
Foreach ($ array as $ value)
{
Echo "$ value ";
Echo"
";
}
?>
Thank you for your criticism!
Author Email: fancao0515@0451.com
[This article is copyrighted by the author and osuo. if you need to reprint it, please indicate the author and its source]
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service