Array Loop Instance in ThinkPHP Template

  • 2021-07-22 09:22:51
  • OfStack

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

In the development process of ThinkPHP, output arrays are often used in templates. All the data from select are 2-dimensional arrays. We can output them with volist tags in templates. Today, the development encountered such a problem: If it is a 2-dimensional array, how to output them in templates? After looking at the development manual, the problem is solved. Share 1, such as this 1-dimensional array:

array(2) {
[2] => string(12) "www.ofstack.com Bowen with pictures "
[3] => string(12) " Default album "
}

With the foreach tag, he can loop 1-dimensional or 2-dimensional arrays, and 1-dimensional arrays are used as follows:

<select id="album_title">
<foreach name="titles" item="vo">
<option value="{$key}">{$vo}</option>
</foreach>
</select>

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


Related articles: