In ThinkPHP, the system provides two tags to facilitate operations: the volist tag and the foreach tag.
volist syntax format:
Note: volist is a double-label statement and needs to be closed.
foreach syntax format:
Note:
foreach is also a double-label statement and needs to be closed.
Difference:
The volist syntax format is roughly the same as the foreach syntax format. In addition to the above name and id attribute pairs, volist also supports more attributes. Yes, such as mod, key, length, etc., and the foreach tag only supports key attribute pairs in addition to the above name and item. It can be understood that the foreach tag is a simplified version of the volist tag.
It is recommended to use the volist tag as much as possible in actual operations.
Case 1:
Traversal of one-dimensional array
Output display:
Case 2:
Traversal of two-dimensional array
assign('array',$array); $this -> assign('array2',$array2); $this -> display(); }
Output display:
More related ThinkPHP For knowledge, please visit ThinkPHP Tutorial!
The above is the detailed content of Two methods of loop traversal in ThinkPHP (volist and foreach tags). For more information, please follow other related articles on the PHP Chinese website!