php循环递归数组入门例子

发布时间:2020-09-25编辑:脚本学堂
php数组循环输出结果,php数组递归遍历的实例代码,有需要的朋友参考下。

例子:
 

复制代码 代码示例:

private function Fndotoarea($oid){
  $oid = $this->CHTID($oid);
  $arrtaff = array();
  $arrt =array();
  $arrr = array();
  foreach($this->select("SELECT areaname , tid FROM otoarea WHERE oid = '".$oid."' " ) as $ks){
    $arrr= Array("node"=>$ks["areaname"],"value"=>$ks["tid"]);
  foreach ($this->select("select areaname , tid FROM otoarea WHERE oid = '".$ks["tid"]."' ") as $kr){
    $arrr['nodes'][] = Array("node"=>$kr["areaname"],"value"=>$kr["tid"]);
}
  $nodes = $this->Fndotoarea($ks["tid"]);
  if(!empty($nodes)){
    $arrr["nodes"] = $nodes;
}
  array_push($arrtaff, $arrr);
}
  return $arrtaff;
} // www.jb200.com

/*----*/
private function Fndotoarea($oid){
$oid = $this->CHTID($oid);
$arrtaff = array();
$arrt =array();
$arrr = array();
foreach($this->select("SELECT areaname , tid FROM otoarea WHERE oid = '".$oid."' " ) as $ks){
$arrr= Array("node"=>$ks["areaname"],"value"=>$ks["tid"]);
foreach ($this->select("select areaname , tid FROM otoarea WHERE oid = '".$ks["tid"]."' ") as $kr){
$arrr['nodes'][] = Array("node"=>$kr["areaname"],"value"=>$kr["tid"]);
}
$nodes = $this->Fndotoarea($ks["tid"]);
if(!empty($nodes)){
$arrr["nodes"] = $nodes;
}
array_push($arrtaff, $arrr);
}
return $arrtaff;
}