/**
* 获取菜单
* @param number $id
* @return multitype:
*/
public function menu($id = 0) {
$menu = M ( 'menu' );
$arrlist = array (); // 数组必须初始化,否push不进去
$where ['app'] = 'Portal';
$where ['parentid'] = $id;
$where ['status'] = 1;
$parent = $menu->order ( 'listorder asc' )->where ( $where )->select ();//判断是否包含children元素
for($i = 0; $i < count ( $parent ); $i ++) {
$arr ['name'] = $parent [$i] ['name'];
$arr ['id'] = $parent [$i] ['id'];
if($id!=0)
{
$arr ['link'] = U ( $parent [$i] ['app'] . '/' . $parent [$i] ['model'] . '/' . $parent [$i] ['action'] . '/' . $parent [$i] ['data'] . '/tid/' . $parent [$i] ['parentid'] . '/id/' . $parent [$i] ['id'] );
}

else
{
$arr ['link'] = U ( $parent [$i] ['app'] . '/' . $parent [$i] ['model'] . '/' . $parent [$i] ['action'] . '/' . $parent [$i] ['data'] . '/tid/' . $parent [$i] ['id'] );
}

$arr ['child'] = $this->menu ( $parent [$i] ['id'] );
array_push ( $arrlist, $arr );   //执行完成这个方法后继续进行下一次递归
}
return $arrlist; // 一次递归完成  然后执行 array_push方法  
}

PHP递归算法的更多相关文章

  1. 递归算法经典实例小结(C#实现)

     一 .递归算法简介 在数学与计算机科学中,递归是指在函数的定义中使用函数自身的方法. 递归算法是一种直接或者间接地调用自身算法的过程.在计算机编写程序中,递归算法对解决一大类问题是十分有效的,它往往 ...

  2. 转: JAVA递归算法实例小结

    一.递归算法设计的基本思想是: 对于一个复杂的问题,把原问题分解为若干个相对简单类同的子问题,继续下去直到子问题简单到能够直接求解,也就是说到了递推的出口,这样原问题就有递推得解. 在做递归算法的时候 ...

  3. xml 读取递归算法

    xml 读取递归算法:

  4. 后台返回字符串类型function的处理 (递归算法)

    $(function(){ $.ajax({ type: "post", url: "${ctx}/modules/fos/reference/echart", ...

  5. JAVA递归算法

    1.什么是递归算法 递归算法就是直接或间接调用自己的算法 2.问题1:一列数的规则如下: 1.1.2.3.5.8.13.21.34 ,求第30位数是多少?使用递归实现 public class Fib ...

  6. 【Tree 1】树形结构数据呈现的递归算法实现

    一.基本概况 在我的项目中,常常会用到树形结构的数据,最为明显的就是左边菜单栏,类似于window folder一样的东西. 而我之前一直是借助前端封装好的ZTree等工具实现展示,而后台则通常使用递 ...

  7. N个数全排列的非递归算法

    //N个数全排列的非递归算法 #include"stdio.h" void swap(int &a, int &b) { int temp; temp = a; a ...

  8. 递归算法(一)——akm

    要求 已知akm函数如下: { n+1 while m=0 }                          => Rule I akm(m,n)= { akm(m-1,1) while n ...

  9. C# 递归算法与冒泡

    C# 递归算法求 1,1,2,3,5,8,13···static void Main(string[] args){ int[] cSum = new int[10];for (int i = 0; ...

  10. 递归算法实现10进制到N进制的转换

    #include<iostream> using namespace std; int BaseTrans(int data,int B){ int s; ) ; //结束递归算法 s=d ...

随机推荐

  1. Location 对象的assign()和replace()有什么区别?

    window.location.assign(url) : 加载 URL 指定的新的 HTML 文档. 就相当于一个链接,跳转到指定的url,当前页面会转为新页面内容,可以点击后退返回上一个页面. w ...

  2. Java使用Commons-FileUpload组件实现文件上传最佳方案

    学习的目标 使用commons-fileupload实现文件上传 使用commons-fileupload封装文件上传工具类   什么是commons-fileupload? The CommonsF ...

  3. 03.Curator深入使用

    1.Apache Curator简介     Curator提供了一套Java类库,可以更容易的使用ZooKeeper.ZooKeeper本身提供了Java Client的访问类,但是API太底层,不 ...

  4. java方法的理解、调用栈与异常处理

    一.流程分支 If/else :基于boolean值的双分支 Switch:基于数字(整数.char.byte.枚举).字符串 类型的多分支 Int month =5; Switch 二.方法meth ...

  5. ZOJ 3932 Deque and Balls

    There are n balls, where the i-th ball is labeled as pi. You are going to put n balls into a deque. ...

  6. HDU_5532_Almost Sorted Array

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  7. POJ3150—Cellular Automaton(循环矩阵)

    题目链接:http://poj.org/problem?id=3150 题目意思:有n个数围成一个环,现在有一种变换,将所有距离第i(1<=i<=n)个数小于等于d的数加起来,对m取余,现 ...

  8. 服务器端IO模型的简单介绍及实现

    https://mp.weixin.qq.com/s?src=3&timestamp=1541726441&ver=1&signature=xPSye3v7miF7aVeLHb ...

  9. About LabView

    Recently I am running an experiment. Because the lab has only NI devices, I have to learn to use the ...

  10. C++开源库集合

    | Main | Site Index | Download | mimetic A free/GPL C++ MIME Library mimetic is a free/GPL Email lib ...