Home > PHP Framework > ThinkPHP > body text

Two methods of loop traversal in ThinkPHP (volist and foreach tags)

藏色散人
Release: 2020-01-22 14:12:45
forward
5141 people have browsed it

Two methods of loop traversal in ThinkPHP (volist and foreach tags)

In ThinkPHP, the system provides two tags to facilitate operations: the volist tag and the foreach tag.

volist syntax format:

Copy after login

Note: volist is a double-label statement and needs to be closed.

foreach syntax format:

Copy after login

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

 assign('array',$array);
   
    $this -> display();
}



test

{$vol} -
{$for} -
Copy after login

Output display:

Two methods of loop traversal in ThinkPHP (volist and foreach tags)

Case 2:

Traversal of two-dimensional array

 assign('array',$array);
    $this -> assign('array2',$array2);
    $this -> display();
    }
Copy after login



test

/*volist循环遍历,嵌套循环*/ {$vo}-

/*foreach循环遍历,嵌套循环*/ {$fo}-
Copy after login

Output display:

Two methods of loop traversal in ThinkPHP (volist and foreach tags)

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!