代码如下:
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: \n"; 
var_dump($c); 
$c = $b + $a; // Union of $b and $a 
echo "Union of \$b and \$a: \n"; 
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" 
}

level分层次输出内容添加leve的更多相关文章

  1. 【记录】尝试用android-logging-log4j去实现log输出内容到sd卡中的文件的功能

    [背景] 折腾: [记录]给Android中添加log日志输出到文件 期间,已经试了: [记录]尝试用android中microlog4android实现log输出到文件的功能 但是不好用. 然后就是 ...

  2. HAproxy增加日志记录功能和自定义日志输出内容、格式

    http://blog.51cto.com/eric1/1854574 一.增加haproxy日志记录功能   1.1 由于数据分析的需要,我们必须打开haproxy日志,记录相关信息. 在配置前,我 ...

  3. [转]用CSS给SVG <use>的内容添加样式

    来源:http://www.w3cplus.com/svg/styling-svg-use-content-css.html?utm_source=tuicool&utm_medium=ref ...

  4. Linux鲜为人知的安全漏洞:不要将输出内容管道给你的shell

    将wget或curl输出的内容管道给bash或者sh是一件非常愚蠢的事,例如像下面这样: wget -O - http://example.com/install.sh | sudo sh 命令解释: ...

  5. Python之向日志输出中添加上下文信息

    除了传递给日志记录函数的参数(如msg)外,有时候我们还想在日志输出中包含一些额外的上下文信息.比如,在一个网络应用中,可能希望在日志中记录客户端的特定信息,如:远程客户端的IP地址和用户名.这里我们 ...

  6. SpringMVC——使用RequestDispatcher.include()和HttpServletResponseWrapper动态获取jsp输出内容

    介绍本篇内容前,先抛出我遇到的问题或者说是需求!(精读阅读本篇可能花费您15分钟,略读需5分钟左右) 一:需求说明 有一个Controller有两个方法 第一个方法通过指定的路径和参数去渲染jsp内容 ...

  7. 【转】Python之向日志输出中添加上下文信息

    [转]Python之向日志输出中添加上下文信息 除了传递给日志记录函数的参数(如msg)外,有时候我们还想在日志输出中包含一些额外的上下文信息.比如,在一个网络应用中,可能希望在日志中记录客户端的特定 ...

  8. 使用feof()判断文件结束时会多输出内容的原因

    这是原来的代码: #include <stdio.h>int main(){    FILE * fp;    int ch;    fp = fopen("d:\\aaaaa\ ...

  9. Python 日志输出中添加上下文信息

    Python日志输出中添加上下文信息 除了传递给日志记录函数的参数(如msg)外,有时候我们还想在日志输出中包含一些额外的上下文信息.比如,在一个网络应用中,可能希望在日志中记录客户端的特定信息,如: ...

随机推荐

  1. [工作中的设计模式]备忘录模式memento

    一.模式解析 备忘录对象是一个用来存储另外一个对象内部状态的快照的对象.备忘录模式的用意是在不破坏封装的条件下,将一个对象的状态捕捉(Capture)住,并外部化,存储起来,从而可以在将来合适的时候把 ...

  2. Thymeleaf 集成spring

    Thymeleaf 集成spring 如需先了解Thymeleaf的单独使用,请参考<Thymeleaf模板引擎使用>一文. 依赖的jar包 Thymeleaf 已经集成了spring的3 ...

  3. vector初始化

    对vector对象来说,直接初始化的方式适用于3种情况:1.初始值已知且数量少:2.初始值是另一个vector对象的副本:3.所有元素的初始值都一样.此外还有一种更常见的情况是4.创建一个vector ...

  4. C# 词法分析器(六)构造词法分析器

    系列导航 (一)词法分析介绍 (二)输入缓冲和代码定位 (三)正则表达式 (四)构造 NFA (五)转换 DFA (六)构造词法分析器 (七)总结 现在最核心的 DFA 已经成功构造出来了,最后一步就 ...

  5. 每天一个linux命令--locate

    linux下,不知道自己安装的程序放在哪里了,可以使用locate命令进行查找. [hongye@dev107 ~]$ locate activemq.xml /home/hongye/hongyeC ...

  6. CodeForceS#276-B(求最大值)

    B. Valuable Resources   Many computer strategy games require building cities, recruiting army, conqu ...

  7. iOS学习33之可视化编程-StoryBoard

    1. storyBoard与xib 1> 概述 iOS下可视化编程分为两种方式: xib 和 storyboard 在使用 xib 和 storyboard 创建 GUI 过程中,以 XML 文 ...

  8. C#数组的声明方式

    C#数组的五种声明方式 一.声明一个未经初始化的数组引用,以后可以把这引用初使化为一个数组实例 int[] intArray; intArray = new int[10]; 注:数组的引用必须以相同 ...

  9. Codeforces Round #244 (Div. 2) B. Prison Transfer

    题目是选出c个连续的囚犯,而且囚犯的级别不能大于t #include <iostream> using namespace std; int main(){ int n,t,c; cin ...

  10. ACM: HDU 1028 Ignatius and the Princess III-DP

     HDU 1028 Ignatius and the Princess III Time Limit:1000MS     Memory Limit:32768KB     64bit IO Form ...