SoFunction
Updated on 2025-03-10

Array loop instance in ThinkPHP template

This article describes the implementation method of array loop in ThinkPHP template. Share it for your reference. The specific implementation method is as follows:

During the development of ThinkPHP, output arrays are often used in templates. Generally, the data selected is a two-dimensional array. We can output it by using the volist tag in the template. Today, we encountered a problem with the development: If it is a two-dimensional array, how can we output it in the template? After checking the development manual, the problem was solved. Let me share it, such as a one-dimensional array:

Copy the codeThe code is as follows:
array(2) {
[2] => string(12) "Blog post picture"
[3] => string(12) "Default Album"
}

When using the foreach tag, it can loop one-dimensional or two-dimensional arrays, and one-dimensional arrays are used like this:

Copy the codeThe code is as follows:
<select >
<foreach name="titles" item="vo">
<option value="{$key}">{$vo}</option>
</foreach>
</select>

I hope this article will be helpful to everyone's ThinkPHP framework programming.