Recursive problem of sub-column

Source: Internet
Author: User
static public function Get ($parentid = 0, $array = Array (), $level = 0, $add = 2, $repeat = ') {$str _repeat = ';        if ($level) {for ($j = 0; $j < $level; $j + +) {$str _repeat. = $repeat;    }} $newarray = Array ();    $temparray = Array (); foreach ((array) $array as $v) {if ($v [' parent_id '] = = $parentid) {$newarray [] = array (' ID ' =&G T $v [' id '], ' catalog_name ' = $v [' catalog_name '], ' catalog_name_alias ' + $v [' Catalog_name_alias '], ' parent_id ' =& Gt $v [' parent_id '], ' level ' = $level, ' sort_order ' + $v [' sort_order '], ' seo_keywords ' + $v [' seo_keywords '], ' s Eo_description ' + $v [' seo_description '], ' attach_file ' + $v [' attach_file '], ' attach_thumb ' = $v [' attach_th Umb '], ' status_is ' = $v [' status_is '], ' data_count ' = ' = ' $v [' data_count '], ' display_type ' + $v [' Display_type '] , ' menu_is ' = $v [' menu_is '], ' template_list ' + $v [' template_list '], ' acl_browser ' = $v [' Acl_browser '], ' acl_operate ' = $v [' acl_operate '], ' template_page ' and ' = ' $v [' template_page '], ' template_show ' = > $v [' template_show '], ' create_time ' + $v [' create_time '], ' str_repeat ' + $str _repeat, ' page_size ' + = $v ['            Page_size ']);            $temparray = Self::get ($v [' id '], $array, ($level + $add));            if ($temparray) {$newarray = Array_merge ($newarray, $temparray); }}} return $newarray;}

The above code in the catalog model, do not understand the wrong should be recursive to get the sub-column such
Now I call the goods

Catalog::get($catalogArr['id'],$catalogArr,2,2,'>>')

Returnarray(0) { }

$catalogArr`打印出来的内容`array(22) { ["id"]=> string(2) "11" ["catalog_name"]=> string(12) "工作动态" ["catalog_name_alias"]=> string(4) "gzdt" ["parent_id"]=> string(1) "0" ["level"]=> int(0) ["sort_order"]=> string(1) "1" ["seo_keywords"]=> string(12) "工作动态" ["seo_description"]=> string(12) "工作动态" ["attach_file"]=> string(0) "" ["attach_thumb"]=> string(0) "" ["status_is"]=> string(1) "Y" ["data_count"]=> string(1) "0" ["display_type"]=> string(4) "list" ["menu_is"]=> string(1) "N" ["template_list"]=> string(9) "list_text" ["acl_browser"]=> string(0) "" ["acl_operate"]=> string(0) "" ["template_page"]=> string(9) "list_page" ["template_show"]=> string(9) "show_post" ["create_time"]=> string(10) "1409390084" ["str_repeat"]=> string(0) "" ["page_size"]=> string(2) "10" }

Ask me to call it that right? " Why can't I get a sub-column?

Reply content:

static public function Get ($parentid = 0, $array = Array (), $level = 0, $add = 2, $repeat = ') {$str _repeat = ';        if ($level) {for ($j = 0; $j < $level; $j + +) {$str _repeat. = $repeat;    }} $newarray = Array ();    $temparray = Array (); foreach ((array) $array as $v) {if ($v [' parent_id '] = = $parentid) {$newarray [] = array (' ID ' =&G T $v [' id '], ' catalog_name ' = $v [' catalog_name '], ' catalog_name_alias ' + $v [' Catalog_name_alias '], ' parent_id ' =& Gt $v [' parent_id '], ' level ' = $level, ' sort_order ' + $v [' sort_order '], ' seo_keywords ' + $v [' seo_keywords '], ' s Eo_description ' + $v [' seo_description '], ' attach_file ' + $v [' attach_file '], ' attach_thumb ' = $v [' attach_th Umb '], ' status_is ' = $v [' status_is '], ' data_count ' = ' = ' $v [' data_count '], ' display_type ' + $v [' Display_type '] , ' menu_is ' = $v [' menu_is '], ' template_list ' + $v [' template_list '], ' acl_browser ' = $v [' Acl_browser '], ' acl_operate ' = $v [' acl_operate '], ' template_page ' and ' = ' $v [' template_page '], ' template_show ' = > $v [' template_show '], ' create_time ' + $v [' create_time '], ' str_repeat ' + $str _repeat, ' page_size ' + = $v ['            Page_size ']);            $temparray = Self::get ($v [' id '], $array, ($level + $add));            if ($temparray) {$newarray = Array_merge ($newarray, $temparray); }}} return $newarray;}

The above code in the catalog model, do not understand the wrong should be recursive to get the sub-column such
Now I call the goods

Catalog::get($catalogArr['id'],$catalogArr,2,2,'>>')

Returnarray(0) { }

$catalogArr`打印出来的内容`array(22) { ["id"]=> string(2) "11" ["catalog_name"]=> string(12) "工作动态" ["catalog_name_alias"]=> string(4) "gzdt" ["parent_id"]=> string(1) "0" ["level"]=> int(0) ["sort_order"]=> string(1) "1" ["seo_keywords"]=> string(12) "工作动态" ["seo_description"]=> string(12) "工作动态" ["attach_file"]=> string(0) "" ["attach_thumb"]=> string(0) "" ["status_is"]=> string(1) "Y" ["data_count"]=> string(1) "0" ["display_type"]=> string(4) "list" ["menu_is"]=> string(1) "N" ["template_list"]=> string(9) "list_text" ["acl_browser"]=> string(0) "" ["acl_operate"]=> string(0) "" ["template_page"]=> string(9) "list_page" ["template_show"]=> string(9) "show_post" ["create_time"]=> string(10) "1409390084" ["str_repeat"]=> string(0) "" ["page_size"]=> string(2) "10" }

Ask me to call it that right? " Why can't I get a sub-column?

Paste one of My code:

/**     * 返回多层栏目     * @param $data 操作的数组     * @param int $pid 一级PID的值     * @param string $html 栏目名称前缀     * @param string $fieldPri 唯一键名,如果是表则是表的主键     * @param string $fieldPid 父ID键名     * @param int $level 不需要传参数(执行时调用)     * @return array     */    static public function channelLevel($data, $pid = 0, $html = " ", $fieldPri = 'cid', $fieldPid = 'pid', $level = 1)    {        if (empty($data)) {            return array();        }        $arr = array();        foreach ($data as $v) {            if ($v[$fieldPid] == $pid) {                $arr[$v[$fieldPri]] = $v;                $arr[$v[$fieldPri]]['_level'] = $level;                $arr[$v[$fieldPri]]['_html'] = str_repeat($html, $level - 1);                $arr[$v[$fieldPri]]["_data"] = self::channelLevel($data, $v[$fieldPri], $html, $fieldPri, $fieldPid, $level + 1);            }        }        return $arr;    }

Landlord can look down

  • Related Article

    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.