• 多为数组转换成一维递归



    //静态变量是只存在于函数作用域中的变量,注释:执行后这种变量不会丢失(下次调用这个函数时,变量仍会记着原来的值)
    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);
    foreach($array as $value){
        echo "<h5>$value</h5>";
        echo "<br>";
    }


    //采用数组引用来实现,这样比上一种要好哦
    function array_multi2single($array,&$rs = array()){
        foreach($array as $value){
            if(is_array($value)){
                array_multi2single($value$rs);
            }
            else
            $rs[]=$value;
        }
    }

    $array=array("1"=>array("A","B","C",array("D","E")),"2"=>array("F","G","H","I"));
    array_multi2single($array$rs);

    print_r($rs);

  • 相关阅读:
    button theme
    Container详解
    flutter控件之ExpansionPanelList
    flutter屏幕适配
    Flutter 获取控件尺寸和位置
    Dart
    异步async、await和Future的使用技巧
    flutter key
    Flutter 控件之 Routes 和 Navigator. [PopupRoute]
    flutter
  • 原文地址:https://www.cnblogs.com/siqi/p/2667018.html
Copyright © 2020-2023  润新知