Functions of converting multidimensional arrays into one-dimensional arrays using recursion

Source: Internet
Author: User
Tags foreach array arrays function prototype functions
Function Name: Array_multi2single
Function prototype: array array_multi2single (array)
Implementation function: The value of a multidimensional array is stored in a one-dimensional array without saving the key.

<?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 Test Section
$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>";

}

?>

You are welcome to criticize and correct me!

Author email:fancao0515@0451.com


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.