zoukankan      html  css  js  c++  java
  • ecmall中一个递归的例子

        function import_resource($resources, $spec_type = null)
        {
            $headtag = '';
            if (is_string($resources) || $spec_type)
            {
                !$spec_type && $spec_type = 'script';
                $resources = $this->_get_resource_data($resources);
                foreach ($resources as $params)
                {
                    $headtag .= $this->_get_resource_code($spec_type, $params) . "\r\n";
                }
                $this->headtag($headtag);
            }
            elseif (is_array($resources))
            {
                foreach ($resources as $type => $res)
                {
                    $headtag .= $this->import_resource($res, $type); //递归导入
                }
                $this->headtag($headtag);
            }
    
            return $headtag;
        }

     又是一个递归

        /**
         * 把某分类及其上级分类加到数组前
         */
        function get_parents(&$parents, $id)
        {
            $data = $this->get(intval($id));
            array_unshift($parents, array('cate_id' => $data['cate_id'], 'cate_name' => $data['cate_name'], 'code' => $data['code']));
            if ($data['parent_id'] > 0)
            {
                $this->get_parents($parents, $data['parent_id']);
            }
        }
    
        /**
         * 获取父级的名称,自己写的一个递归,相当的不容易啊
         */
        function get_parents_name($region_id){
            static $parents = array();
            $region = $this->get($region_id);
            if (!empty($region))
            {
                $parents[] = $region;
                if ($region['parent_id'])
                {
                    $this->get_parents_name($region['parent_id']);
                }
            }
            return $parents;
        }

      

  • 相关阅读:
    第十一节 CSS引入的三种方式
    第十节 表单
    第九节 页面布局(简历)
    第八节 HTML表格
    第七节 列表标签
    第六节 链接标签
    第五节 插入图的img标签
    WordPress 全方位优化指南(下)
    Cloud Insight!StatsD 系监控产品新宠!
    WordPress 全方位优化指南(上)
  • 原文地址:https://www.cnblogs.com/linksgo2011/p/2969533.html
Copyright © 2011-2022 走看看