DeTechn Blog

PHP递归查询获取子项目,适用于无极分类

<?php
// 引用的外部类及方法参见我的 php-library 项目
function getSubRecur($pid){
  global $pdo,&nbsp;$func;
  $retData = array();
  $curData&nbsp;=&nbsp;array($pid);
  while(count($curData)>0){
    $curStr&nbsp;=&nbsp;implode(&#39;,&#39;,&nbsp;$curData);
    $sql&nbsp;=&nbsp;&quot;select&nbsp;id&nbsp;from&nbsp;kjj_group_info&nbsp;where&nbsp;pid&nbsp;in&nbsp;({$curStr})";
    $nextData&nbsp;=&nbsp;$pdo->fetchData($sql);
    $retData&nbsp;=array_merge($retData, $curData);
    $curData&nbsp;=$func->arrayColumn($nextData, 'id');
  }
  return $retData;
}
?>

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »