smarty模板中如何写循环
smarty模板中怎么写循环
研究了半天教程,好像所有的循环都是针对传入数组的
我的问题是这样的:
在一个传入数组中,有8个元素是从i0到i7命名的,现在需要对这个8个元素进行处理
因为这个数组中还包含其它元素,因此不能针对数组进行循环处理
我想的是类似于这样
for ($i=0; $i {
echo $arr["i$i"];
}
我在smarty中嵌入这段php代码,结果好像是获取不过$arr这个变量,导致没有输出。
不知道这个在smarty中该如何实现,请高手指点
------解决方案--------------------
还有个思路你可以在php页面写个数组,里面分别是i0-i7,然后循环这个数组,在里面打印有数据的数组。。
比如你传的数组是$i
- PHP code
{foreach from=$i item=item} {$arr[$item]}<br> <br><font color="#e78608">------解决方案--------------------</font><br>
- PHP code
foreach(from=$arr; key=k item=v){ 键:{$k}:值{$v} } <br><font color="#e78608">------解决方案--------------------</font><br>{section name="fooo" loop=$new_re_j}<br>{$new_re_id[fooo]}<br>{/section}<br> <br><font color="#e78608">------解决方案--------------------</font><br>在smarty中嵌套循环吧 <br><font color="#e78608">------解决方案--------------------</font><br>section foreach循环;<br> <br><font color="#e78608">------解决方案--------------------</font><br>{foreach from=$i item=item}<br>{$arr[$item]}<br><br><br><br> <br><font color="#e78608">------解决方案--------------------</font><br>为什么要在smarty中做呢?在php中处理完,然后输出数组显示不是更好吗? <br><font color="#e78608">------解决方案--------------------</font><br>smarty模板里面一般都是用foreach进行循环<br><br>{{foreach from=$test key=key item=i}}<br> <br>{{/foreach}} <div class="clear"> </div>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

1. The difference between Iterator and foreach is the polymorphic difference (the bottom layer of foreach is Iterator) Iterator is an interface type, it does not care about the type of collection or array; both for and foreach need to know the type of collection first, even the type of elements in the collection; 1. Why is it said that the bottom layer of foreach is the code written by Iterator: Decompiled code: 2. The difference between remove in foreach and iterator. First, look at the Alibaba Java Development Manual, but no error will be reported in case 1, and an error will be reported in case 2 (java. util.ConcurrentModificationException) first

The steps for PHP to determine the number of the foreach loop: 1. Create an array of "$fruits"; 2. Create a counter variable "$counter" with an initial value of 0; 3. Use "foreach" to loop through the array, and Increase the value of the counter variable in the loop body, and then output each element and their index; 4. Output the value of the counter variable outside the "foreach" loop to confirm which element the loop reaches.

This article will explain in detail how PHP returns an array after key value flipping. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP Key Value Flip Array Key value flip is an operation on an array that swaps the keys and values in the array to generate a new array with the original key as the value and the original value as the key. Implementation method In PHP, you can perform key-value flipping of an array through the following methods: array_flip() function: The array_flip() function is specially used for key-value flipping operations. It receives an array as argument and returns a new array with the keys and values swapped. $original_array=[

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

This article will explain in detail about the current element in the array returned by PHP. The editor thinks it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. Get the current element in a PHP array PHP provides a variety of methods for accessing and manipulating arrays, including getting the current element in an array. The following introduces several commonly used techniques: 1. current() function The current() function returns the element currently pointed to by the internal pointer of the array. The pointer initially points to the first element of the array. Use the following syntax: $currentElement=current($array);2.key() function key() function returns the array internal pointer currently pointing to the element

How to iterate through the properties of an object using the forEach function? In JavaScript, we often need to traverse the properties of objects. If you want to use a concise way to iterate over the properties of an object, the forEach function is a very good choice. In this article, we will explain how to use the forEach function to iterate over the properties of an object and provide specific code examples. First, let's understand the basic usage of the forEach function. forEach function is Java

In modern web development, the separation of front-end and back-end has become a very popular trend, which allows developers to better organize projects and improve the efficiency of project development. PHP and Smarty are two very commonly used technologies, which can be used to achieve front-end and back-end separation development. This article will introduce how to use PHP and Smarty to achieve front-end and back-end separation development. What is front-end and back-end separation development? In traditional web development, the front-end is mainly responsible for the presentation of the page and the logic of interaction with the back-end. The backend is mainly responsible for the business

Nowadays, website development is inseparable from an important component-template engine. A template engine refers to a tool that combines page templates and data to generate HTML code with a specific format. In various website development frameworks, the template engine is an essential component, because the template engine can greatly reduce the duplication of code and improve the dynamics of the page. One of the most common and popular template engines is Smarty. Smarty is a DSL (DomainSpecif
