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; }