PHP Infinite recursive function

Source: Internet
Author: User
 
/**  * infinite recursive drop-down selection box  * @param $data    array  * @param $pid     parent ID  * @param int $t   Cycles: Action indent  * @param int $selected selected subscript  * @return string  * @author Zhengjingqiang  * @email s cenewood@163.com  * @date 2015-10-22  */function html_options ($data =array (), $pid =0, $t =-1, $selected =0) {&
nbsp;   $html _options = ';
    $t + +;
    $nbspstr = str_repeat ('   ', $t * 4);     if ($data) {        foreach ($data as $k => $v) {  &N bsp;         if ($pid = = $v [' pid ']) {                //Determine if it is the last Drop-down tab                  $symbol _str = (count ($data) = = ($k + 1))?
' ┗ ': ' Out ';                //Decide whether to select                  $selected _str = ($selected = = $v [' id '])?
' Selected= ' selected ': ';                //dropdown selection box data                  $html _options. = ' <option Value= "'. $v [' id ']. "'. $selected _str. ' > '. $nbspstr. $symbol _str. $v [' name '].
' </option> ';                //Infinite loop lookup subset                  $html _options. = Html_
Options ($data, $v [' id '], $t, $selected);
           }        }
   }     return $html _options; /**  * Two-dimensional array recursive  * @param array $arr  * @return array  * @author zhengjingqiang  * @email scenewood@163.com function C Ategory ($arr = Array ()) {    $info = array ();     if (count ($arr) > 0) {  &nbsp ;     foreach ($arr as $k => $vo) {             if ($vo [' pid '] = = 0) {                 foreach ($arr as $v) {                     if ($v [' pid '] = = $VO [' id ']) {                         $vo [' children '] = $v
;                     }                }                 $info
[] = $vo;
           }        }
   }     return $info; /**  * Infinite Classification  * @param $array  * @param int $pid  * @return array  * @author Zhengjingqiang &n bsp;* @email scenewood@163.com  */function Menutree ($array, $pid) {    $arr = array ();   & nbsp foreach ($array as $v) {        if ($v [' pid '] = = $pid) {    &nbs
p;       $tem = Menutree ($array, $v [' id ']);            //Determine if there is a child array      
       $tem && $v [' child '] = $tem;
            $arr [] = $v;        }    }     return $arr;
 }


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.