PHP unlimited classification table to div

Source: Internet
Author: User
PHP unlimited classification table to div reference URL
Http://www.qunfei.com/htmls/webdevelop/php/2012/0116/819.html


function dafenglei_arr($m,$id){global $class_arr;global $ppid;if($id=="") $id=0;$n = str_pad('',$m,'-',STR_PAD_RIGHT);$n = str_replace("-","  ",$n);for($i=0;$i
 
  \n";echo "".$n."|--".$class_arr[$i]['className'].$m."\n";echo "\n";dafenglei_arr($m+1,$class_arr[$i]['classid']);}}}
 



The output format is

Topic 1
Topic 1-1
Topic 1-2
Topic 1-3
Topic 1-3-1




Convert


  • Topic 1

    • Topic 1-1

    • Topic 1-2

    • Topic 1-3

      • Topic 1-3-1





  • ... And so on.




Reply to discussion (solution)

Please provide test data

Http://bbs.csdn.net/topics/390398703 with this post combined...

It is an infinite classification. the infinite classification is based on the table display, and a space is added before the td to distinguish the first-level and second-level columns.

I want to use p to implement

Array
(
[2] => Array
(
[Classid] => 6
[Classfid] => 0
[Classname] => Topic 1

)

[1] => Array
(
[Id] => 7
[Classfid] => 6
[Classname] => Topic 1-1

)

[0] => Array
(
[Classid] => 10
[Classfid] => 7
[Classname] => Topic 1-1-1

)

)


Almost all of this data

Function add _ ($ num ){
$ Str = '';
For ($ I = 1; $ I <= $ num; $ I ++ ){
$ Str. = '';
}
Return $ str;
}
Function tree ($ _ arr, $ I =-1 ){
$ _ Tree = '';
$ I ++;
Foreach ($ _ arr as $ _ key => $ _ value ){
If (is_array ($ _ value )){
$ _ Tree. = add _ ($ I). $ _ key .'
';
$ _ Tree. = tree ($ _ value, $ I );
} Else {
$ _ Tree. = add _ ($ I). $ _ key. '=>'. $ _ value .'
';
}
}
Return $ _ tree;
}
Try these two functions and add some HTML tags.

$ Ar = array (2 => array ('classid' => '6', 'classfid' => '0', 'classname' => 'column 1 ',), 1 => array ('id' => '7', 'classfid' => '6', 'classname' => 'column 1-1 ',), 0 => array ('classid '=> '10', 'classfid' => '7', 'classname' => 'column 1-1-1',),); echo'
 
 
    '; Foreach ($ ar as $ item) {if ($ item ['classfid'] = 0) $ deep = 0; $ t = substr_count ($ item ['classname'], '-'); if ($ t <$ deep) echo'
'; If ($ t> $ deep) echo'
    '; Echo'
  • '. $ Item ['classname']; $ deep = $ t;} while ($ deep --) echo'
';
  • Topic 1
    • Topic 1-1
      • Topic 1-1-1

    Incomplete data may not be differentiated "-".

    Array ([0] => Array ([id] => 10 [pid] => 0 [ppid] => 7 [m_title] => System classification [m_flag] => 1 [m_type] => 0 [m_url] => [m_lage] => 0 [m_seotitle] => [m_seokey] => [m_seodesc] => [m_sort] => 0 [m_time] => 0000-00-00:00:00) [1] => Array ([id] => 9 [pid] => 0 [ppid] => 6 [m_title] => sort management [m_flag] => 0 [m_type] => 0 [m_url] => [m_lage] => 0 [m_seotitle] => [m_seokey] => [m_seodesc] => [m_sort] => 0 [m_time] => 0000-00-00 00:00:00) [2] => Array ([id] => 8 [pid] => 0 [ppid] => 6 [m_title] => logon log [m_flag] => 0 [m_type] => 0 [m_url] => [m_lage] => 0 [m_seotitle] => [m_seokey] => [m_seodesc] => [m_sort] => 0 [m_time] => 0000-00-00 00:00:00) [3] => Array ([id] => 7 [pid] => 0 [ppid] => 6 [m_title] => System Information [m_flag] => 0 [m_type] => 0 [m_url] => 11 [m_lage] => 0 [m_seotitle] => [m_seokey] => [m_seodesc] => [m_sort] => 10 [m_time] => 0000-00-00 00:00:00) [4] => Array ([id] => 6 [pid] => 0 [ppid] => 0 [m_title] => Website Management [m_flag] => 1 [m_type] => 4 [m_url] => 11 [m_lage] => 1 [m_seotitle] => [m_seokey] => [m_seodesc] => [m_sort] => 10 [m_time] => 0000-00-00 00:00:00) [5] => Array ([id] => 5 [pid] => 0 [ppid] => 2 [m_title] => text link [m_flag] => 0 [m_type] => 22 [m_url] => [m_lage] => 0 [m_seotitle] => [m_seokey] => [m_seodesc] => [m_sort] => 10 [m_time] = >) [6] => Array ([id] => 4 [pid] => 0 [ppid] => 0 [m_title] => about [m_flag] => 0 [m_type] => 0 [m_url] => [m_lage] => 0 [m_seotitle] => [m_seokey] => [m_seodesc] => [m_sort] => 10 [m_time] = >) [7] => Array ([id] => 1 [pid] => 0 [ppid] => 0 [m_title] => News Center [m_flag] => 0 [m_type] => 0 [m_url] => [m_lage] => 0 [m_seotitle] => [m_seokey] => [m_seodesc] => [m_sort] => 10 [m_time] = >) [8] => Array ([id] => 2 [pid] => 0 [ppid] => 0 [m_title] => link [m_flag] => 0 [m_type] => 0 [m_url] => [m_lage] => 0 [m_seotitle] => [m_seokey] => [m_seodesc] => [m_sort] => 102 [m_time] => ))


    This is the result.


    I want to convert the above result


       
       
    • Superior file
      • Transportation Inspection Department
      • Labor Department
      • Finance Department
      • Security Supervision Department
      • Logistics Department
    • Various systems
      • Repair Management
      • Operation Management
      • Security management
      • Integrated Management
      • Training Management
      • Technology Management


    The infinite classification form of p + CSS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.