assign("a1",$arr);在htm模板文件中如何只输出"/> assign("a1",$arr);在htm模板文件中如何只输出">

请问smarty只输出数组的一项的方法,不用循环

WBOY
Release: 2016-06-13 13:46:39
Original
768 people have browsed it

请教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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template