把多維數組轉化爲二維數組

/**
     *  把多維數組轉化爲二維數組
     * @staticvar array $result
     * @param <type> $data
     * @return <type>
     */
   public  function array_multi2single($data){
        static $result=array();
        foreach($data as $value){
            if(isset($value['children']) && is_array($value['children'])){
                $temp   =   $value;unset($temp['children']);
                $result[$value['id']] =   $temp;
                $this->array_multi2single($value['children']);
            }else{
                $result[$value['id']]=$value;
            }
        }


        return $result;
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章