Php recursive method for infinite classification Example _php tutorial

Source: Internet
Author: User
Array:

$items = Array (
Array (' id ' = = 1, ' pid ' = + 0, ' name ' = ' 11 '),
Array (' id ' = = ' pid ' = 0, ' name ' = ' www.111cn.net ' 12 '),
Array (' id ' = = 2, ' pid ' = + 1, ' name ' = ' two ' Level 21 '),
Array (' id ' = +, ' pid ' = ' = ', ' name ' = ' two ' 22 '),
Array (' id ' = = 3, ' pid ' = + 1, ' name ' = ' two ' level 23 '),
Array (' id ' = ' = ', ' pid ' = ' = ', ' name ' = ' two ' 24 '),
Array (' id ' = ' + ', ' pid ' = ' + ', ' name ' = ' three ', ' Level 31 '),
Array (' id ' = = 9, ' pid ' = + 1, ' name ' = ' two ' Level 25 '),
);

< td="">
The code is as follows

Function:

function Formattree ($array, $pid = 0) {
$arr = Array ();
$tem = Array ();
foreach ($array as $v) {
if ($v [' pid '] = = $pid) {
$tem = Formattree ($array, $v [' id ']);
Determine if a subarray exists
$tem && $v [' son '] = $tem;
$arr [] = $v;
}
}
return $arr;
}

< td="">
The code is as follows

Where the array must contain the ID and PID to specify the hierarchical relationship between the array values

Articles you may be interested in
    • The implementation of infinite Classification & tree-type Forum
    • PHP MySQL implements infinite class classification tree display classification relationship
    • Unlimited categories of articles
    • Unlimited classification
    • The realization method of infinite classification and tree-type forum
    • PHP Infinite Class classification code
    • PHP Infinite Class Classification [recursive method]
    • Infinite class Classification [pre-sorting traversal tree algorithm]
    • An algorithm for infinite classification of PHP
    • Ecshop Commodity Unlimited Class Code

http://www.bkjia.com/PHPjc/738522.html www.bkjia.com true http://www.bkjia.com/PHPjc/738522.html techarticle Array: The code is as follows $items = array (' id ' = 1, ' pid ' = 0, ' name ' = ' Level One '), array (' id ' = all, ' pid ' = 0, ' name ' = ' WWW.111CN . NET level '), array (' id ' = 2, ' pid ' = 1,...

  • 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.