assign("a1",$arr);在htm模板文件中如何只输出" /> assign("a1",$arr);在htm模板文件中如何只输出">
Home Backend Development PHP Tutorial 请问smarty只输出数组的一项的方法,不用循环

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

Jun 13, 2016 pm 01:46 PM
arr assign foreach quot smarty

请教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
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to determine the number of foreach loop in php How to determine the number of foreach loop in php Jul 10, 2023 pm 02:18 PM

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? What is the difference between using foreach and iterator to delete elements when traversing Java ArrayList? Apr 27, 2023 pm 03:40 PM

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 an array with key values ​​flipped Mar 21, 2024 pm 02:10 PM

PHP returns an array with key values ​​flipped

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决 Jun 13, 2016 am 10:23 AM

php提交表单通过后,弹出的对话框怎样在当前页弹出,该如何解决

PHP returns the current element in an array PHP returns the current element in an array Mar 21, 2024 pm 12:36 PM

PHP returns the current element in an array

Solve golang error: cannot assign to 'x', solution Solve golang error: cannot assign to 'x', solution Aug 20, 2023 pm 02:22 PM

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

How to iterate through the properties of an object using the forEach function? How to iterate through the properties of an object using the forEach function? Nov 18, 2023 pm 06:10 PM

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 How to use PHP and Smarty to achieve front-end and back-end separation development Jun 25, 2023 pm 01:46 PM

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

See all articles