Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php递归算法应用实例

php递归算法应用实例

发布时间:2018-01-11   编辑:www.jquerycn.cn
分享一个php递归算法的实现代码,学习下php递归算法的用法,不错的例子,有需要的朋友参考下。

例子,php递归算法实例。
 

复制代码 代码示例:
<?php
  function Type($tid) {
   $rs = $this->conn->Execute("SELECT * FROM protype where id=$tid");
  
   if ($rs) {    
     $i = 0;
     $type[] = array();
     while (!$rs->EOF) {
      $type[$i] = $rs->fields;    
      $type[$i]['child'] = $this->GetClass($type[$i]['id']);
      $i++;     
      $rs->MoveNext();
     }
   }
   return $type;
  }
 
  function GetClass($tid) {
   $rs = $this->conn->Execute("SELECT * FROM proclass where tid=$tid");
   if ($rs) {
     $i = 0;
     $class[] = array();
     while (!$rs->EOF) {
      $class[$i] = $rs->fields;
      $class[$i]['child'] = $this->GetPro($class[$i]['id']);
      $i++;     
      $rs->MoveNext();
     }
   }
   return $class;
  }
 
  function GetGroup($cid) {
   $rs = $this->conn->Execute("SELECT * FROM progroup where cid=$cid");
   if ($rs) {
     $i = 0;
     $group[] = array();
     while (!$rs->EOF) {
      $group[$i] = $rs->fields;
      $group[$i]['child'] = $this->GetPro($group[$i]['id']);
      $i++;     
      $rs->MoveNext();
     }
   }
  
   return $group;
  }
 
  function GetPro($cid) {
   $rs = $this->conn->Execute("SELECT * FROM prolist where cid=$cid limit 5");
   if ($rs) {
     $i = 0;
     while (!$rs->EOF) {
      $plist[$i] = $rs->fields;
      $i++;     
      $rs->MoveNext();
     }
   }
  
   return $plist;
  }
 
  function PageHead() {
   $this->GetAdvit();
  
  
   $rs = $this->conn->Execute("SELECT * FROM protype");
  
   if ($rs) {
    
    $i = 0;
    $type[] = array();
    while (!$rs->EOF) {
     $type[$i] = $rs->fields;    
     $type[$i]['child'] = $this->GetClass($type[$i]['id']);
     $i++;     
     $rs->MoveNext();
    }
   }  
  
   $this->smarty->assign("alltype", $type);
   $rs = $this->conn->Execute("SELECT * FROM province");
   if ($rs) { //递归算法 www.jbxue.com
    $i = 0;
    while (!$rs->EOF) {
     $pvc[$i] = $rs->fields;
     $i++;     
     $rs->MoveNext();
    }
   }  
   $this->smarty->assign("pvc", $pvc);
   $this->smarty->display("head.html");
  }

您可能感兴趣的文章:
PHP递归算法实例解析
php递归创建目录小例子
什么是php递归
php递归算法 php递归函数无限级分类
php递归函数使用return问题
一文了解Python中的递归
php递归示例 php递归函数代码
PHP递归算法与应用实例
php递归函数小例子
PHP递归打印数组中所有元素的简单示例代码

关键词: php递归算法  递归算法   
[关闭]