Home > php教程 > php手册 > 利用递归把多维数组转为一维数组的函数

利用递归把多维数组转为一维数组的函数

WBOY
Release: 2016-06-13 12:37:13
Original
778 people have browsed it

函数名称:array_multi2single
函数原形:array array_multi2single(array)
实现功能:把一个多维数组的数值存放到一维数组中,不保存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;
}


//函数测试部分
$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 "
$value
";
    echo "
";

}

?>

欢迎大家批评指正!

作者Email:fancao0515@0451.com


【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】    
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template