Home > Backend Development > PHP Tutorial > Function to convert multi-dimensional array into one-dimensional array using recursion_PHP tutorial

Function to convert multi-dimensional array into one-dimensional array using recursion_PHP tutorial

WBOY
Release: 2016-07-21 16:01:26
Original
1090 people have browsed it

Function name: array_multi2single
Function prototype: array array_multi2single(array)
Implementation function: Store the values ​​of a multi-dimensional array into a one-dimensional array without saving the Key.


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 part
$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 "
";

}

?>

Welcome everyone to criticize and correct!

Author Email: fancao0515@0451.com


[The copyright of this article is jointly owned by the author and Aosuo.com. If you need to reprint, please indicate the author and source]

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316900.htmlTechArticleFunction name: array_multi2single Function prototype: array array_multi2single(array) Implementation function: Store the value of a multi-dimensional array into a In a dimensional array, the Key is not saved. ?php functio...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template