Recursive Function for converting a multi-dimensional array into a one-dimensional array

Source: Internet
Author: User

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.

<? Php

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 "Foreach ($ array as $ value)
{
Echo "Echo "<br> ";

}

?>

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]

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.