thinkphp template volist label nested loop output multidimensional array method, Thinkphpvolist
This article describes the thinkphp template volist label nested loop output multidimensional array method. Share to everyone for your reference, as follows:
The use of nested volist tags in thinkphp enables the output of multidimensional arrays.
Volist nested use
A general two-dimensional array that can be directly looped out with volist tags. For multidimensional arrays, you need to use the volist tag again to nest the loop output for the array members.
To build a multidimensional array:
$food = Array (); $food [0][' Fruits '][0][' fruits1 '] = ' Apple 1 '; $food [0][' Fruits '][0][' fruits2 '] = ' orange 1 '; $food [0][' fruits '] [0] [' fruits3 '] = ' banana 1 '; $food [0][' vegetables '] = ' cabbage 1 '; $food [1][' Fruits '][1][' fruits1 '] = ' Apple 2 '; $food [1][' Fruits '][1][' Fruits2 '] = ' orange 2 '; $food [1][' Fruits '][1][' fruits3 '] = ' banana 2 '; $food [1][' vegetables '] = ' cabbage 2 ';
Use the Print_r () function to print out the array as follows:
Array ( [0] = = Array ([ fruits] = = Array ( [0] = = Array ( [Fruits1] = Apple 1 [FRUITS2] + orange 1 [fruits3] + Banana 1 ) ) [vegetables] + cabbage 1 ) [1] = = Array ( [fruits] = = Array ( [1] = = Array ( [fruits1] = Apple 2 [fruits2] = orange 2 [FRUITS3] + banana 2 ) ) [vegetables] + cabbage 2 ))
Assign the variable to the template in the corresponding module operation (such as Index/display) and output the template:
$this->assign ("Food", $food); $this->display ();
Template tpl/default/index/display.html:
Food varieties:
Fruit 1:{$f [' Fruits1 ']}
Fruit 2:{$f [' Fruits2 ']}
Fruit 3:{$f [' Fruits3 ']}
Vegetables: {$vo [' vegetables ']}
Inside the template, the $food variable is first looped out. Because the member fruits of the $food array is also an array, the $VO [' fruits '] variable is recycled (note that there is no $ symbol).
The output results are as follows:
Food variety: Fruit 1: Apple 1 fruit 2: Orange 1 Fruit 3: Banana 1 Vegetable: Cabbage 1 fruit 1: Apple 2 fruit 2: Orange 2 Fruit 3: Banana 2 vegetable: Cabbage 2
In this way, the array of more dimensions can be looped out.
More interested in thinkphp related content readers can view this site topic: "thinkphp Introductory Tutorial", "thinkphp Common Methods Summary", "Smarty Template Primer Basic Tutorial" and "PHP template technology Summary."
It is hoped that this article is helpful to the PHP program design based on thinkphp framework.
Articles you may be interested in:
- thinkphp volist Tag mod controls certain records of line break bug resolution
- thinkphp the volist tag nesting loop usage Tutorial
- Introduction to Volist label usage in thinkphp
- thinkphp template tags if and eq differences and comparison example analysis
- thinkphp ways to prevent template labels from being parsed using literal
- thinkphp template range Judging output in tags and range label usage
- thinkphp Template Judging output empty label usage
- thinkphp template Judging output defined label usage detailed
- thinkphp template Judging output present label usage detailed
- thinkphp Template Comparison Label usage detailed
- thinkphp Template Switch Label usage example
- thinkphp Template Custom Label usage method
- thinkphp How to use HTML template tags
- thinkphp template loop output volist Label Usage example detailed
http://www.bkjia.com/PHPjc/1113705.html www.bkjia.com true http://www.bkjia.com/PHPjc/1113705.html techarticle thinkphp template volist label nested loop output multidimensional array method, Thinkphpvolist This article describes the thinkphp template volist label nested loop output multidimensional array method. Share to the big ...