Home >CMS Tutorial >PHPCMS >How to use loop tag in phpcms
In phpcms, loops are used a lot, generally in two forms.
The form is as follows:
Form one:
{loop $data $a} {$a} {/loop}
Form two:
{loop $data $a $b} {$a}---{$b} {/loop}
The difference is as follows:
First of all, $data is an array. In the first form, the $data array is like this, "aa", "bb", "cc". In this form, To get the first value aa, we use this code $data[0], to get the second value we use $data[1], and so on.
Form 2, the $data array has an additional key value, which is in this form "a1=>aa", "a2=>bb", "a3=>cc", a1, a2 , a3 is called the key value of $data. If we want to take out the variable value with the key value a1, that is, aa, we can use $data[a1] to get aa. Similarly, $data[a2] also It’s just bb.
Then in PHPCMS, form 1:
In the loop, $a is $data[0], $data[1], $data[2], we directly write {$ a} can loop to get the value of $a.
Form 2:
In the loop, $a is a1, a2, a3 in the above example, and $b is aa, bb, cc in the above example.
The examples are as follows:
Example 1: There are three values "aa", "bb", "cc" in the
$data array, then :
{loop $data $a} {$a} {/loop}
will output aa, bb, cc.
Example 2:
There are three key values in the $data array: "a1=>aa", "a2=>bb", "a3=>cc", Then
{loop $data $a $b} {$a}-{$b}| {/loop}
will output a1-aa|a2-bb|a3-cc|.
Related tutorial recommendations: phpcms tutorial
The above is the detailed content of How to use loop tag in phpcms. For more information, please follow other related articles on the PHP Chinese website!