欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP无限极分类之数组_PHP教程

程序员文章站 2022-04-22 12:51:51
...

PHP无限极分类之数组

 array('id' => 1,'name' => 'name1','pid' => 0),
            2 => array('id' => 2,'name' => 'name2','pid' => 0),
            3 => array('id' => 3,'name' => 'name3','pid' => 1),
            4 => array('id' => 4,'name' => 'name4','pid' => 0),
            5 => array('id' => 5,'name' => 'name5','pid' => 3),
            6 => array('id' => 6,'name' => 'name6','pid' => 3),
    );
 $str = getTree(0);
$str = "";
echo $str;
function getTree($id,$spac=0)
{
    $data = array( 1 => array('id' => 1,'name' => 'name1','pid' => 0),
            2 => array('id' => 2,'name' => 'name2','pid' => 0),
            3 => array('id' => 3,'name' => 'name3','pid' => 1),
            4 => array('id' => 4,'name' => 'name4','pid' => 0),
            5 => array('id' => 5,'name' => 'name5','pid' => 3),
            6 => array('id' => 6,'name' => 'name6','pid' => 3),
    );
    $spac = $spac + 2;
    static $str;
     
    foreach ($data as $k => $v) {
        if ($v['pid'] == $id) {
            $arr[] = $v;
            $str .= "";
            getTree($v['id'],$spac);
 
        }
 
    }
     
    return $str;
}
 
 
 
?>

PHP无限极分类之数组_PHP教程

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1079403.htmlTechArticlePHP无限极分类之数组 ?php$data = array( 1 = array(id = 1,name = name1,pid = 0), 2 = array(id = 2,name = name2,pid = 0), 3 = array(id = 3,name = name3,pid = 1), 4 = array(id...
相关标签: 数组