请问smarty只输出数组的一项的方法,不用循环
Jun 13, 2016 pm 01:46 PM
请教smarty只输出数组的一项的方法,不用循环
$arr=array();
$arr[0]="1";
$arr[1]="2";
$arr[2]="3";
$arr[0]="4";
smarty->assign("a1",$arr);
在htm模板文件中如何只输出数组的某一项 ,我知道用foreach可以循环显示出来,但是我只需要显示一项。
望解答.
------解决方案--------------------
- PHP code
$arr=array(); $arr[0]="1"; $arr[1]="2"; $arr[2]="3"; $arr[0]="4"; foreach($arr as $key=>$val){ if($key=="你要输出的"){ smarty->assign("a1",$arr[$key]); } } <br><font color="#e78608">------解决方案--------------------</font><br>顶 <br><font color="#e78608">------解决方案--------------------</font><br>{$a1.0}或者是 {$a[0]}这样 <br><font color="#e78608">------解决方案--------------------</font><br>{$a1.0}或{$a1[0]} <br><font color="#e78608">------解决方案--------------------</font><br>study! <br><font color="#e78608">------解决方案--------------------</font><br>{$a1.0}这样你需要自己记住数组的下标,很不方便<br>{$a1[0]} 是错的 <br><font color="#e78608">------解决方案--------------------</font><br>是随机的吗?shuffle($a1) <div class="clear"> </div>

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

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

How to determine the number of foreach loop in php

What is the difference between using foreach and iterator to delete elements when traversing Java ArrayList?

PHP returns an array with key values flipped

PHP returns the current element in an array

Solve golang error: cannot assign to 'x', solution

How to iterate through the properties of an object using the forEach function?

How to use PHP and Smarty to achieve front-end and back-end separation development
