• level分层次输出内容添加leve


    代码如下:
    function getSubComments($parent = 0, $level = 0) { 
    $db = &JFactory::getDBO();

    $sql = "..."; // 查询记录的SQL 
    $db->setQuery($sql); 
    $rows = $db->loadObjectList();

    $list = array();

    // 先从数据得到记录集,再对记录添加level, 父层level = 0,它的下级level = 1,如此类推 
    foreach ($rows as $row) { 
    $row->level = $level; 
    $list[] = $row;

    $tmpArr = getSubComments($row->id, $level + 1); // 递归调用 
    if (count($tmpArr)) { 
    foreach ($tmpArr as $tmpRow) { 
    $list[] = $tmpRow; 


    }

    return $list; 
    }

    $list = array(); 
    foreach ($tmpList as $row) { 
    $row->level = 0; 
    $list[] = $row; 
    $tmpList2 = getSubComments($row->id, 1); 
    foreach ($tmpList2 as $row2881064151) { 
    $list[] = $row2; 

    }

    // 按level分层次输出内容 
    if ($row->level) { 
    $pre = ''; 
    for ($n = 0; $n < $row->level; $n++) 
    $pre .= '----';

    echo $pre . '|- '; 

    echo strip_tags($row->content);
     

    代码如下:
    <?php 
    $a = array("a" => "apple", "b" => "banana"); 
    $b = array("a" => "pear", "b" => "strawberry", "c" => "cherry"); 
    $c = $a + $b; // Union of $a and $b 
    echo "Union of $a and $b: "; 
    var_dump($c); 
    $c = $b + $a; // Union of $b and $a 
    echo "Union of $b and $a: "; 
    var_dump($c); 
    ?>

     
    When executed, this script will print the following: 
    Union of $a and $b: 
    代码如下:
    array(3) { 
    ["a"]=> 
    string(5) "apple" 
    ["b"]=> 
    string(6) "banana" 
    ["c"]=> 
    string(6) "cherry" 

    Union of $b and $a: 
    array(3) { 
    ["a"]=> 
    string(4) "pear" 
    ["b"]=> 
    string(10) "strawberry" 
    ["c"]=> 
    string(6) "cherry" 
    }

  • 相关阅读:
    [JLOI2015]有意义的字符串
    二阶常系数线性齐次递推式的特征方程
    CH1812 生日礼物
    CH1809 匹配统计
    CH1808 Milking Grid
    BZOJ4025 二分图
    BZOJ3514 GERALD07加强版
    NOI2014 魔法森林
    WC2006 水管局长数据加强版
    LG3690 【模板】Link Cut Tree 和 SDOI2008 洞穴勘测
  • 原文地址:https://www.cnblogs.com/cbryge/p/6169282.html
Copyright © 2020-2023  润新知