Smarty area loop method in php_PHP tutorial

WBOY
Release: 2016-07-13 09:50:59
Original
819 people have browsed it

How to loop smarty areas in php

This article describes the method of looping smarty areas in php. Share it with everyone for your reference. The specific implementation method is as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Smarty Test

{foreach key=key1 item=item1 from=$array1}

{/foreach}

{$key1} {$item1}

1 2

3

4

1

2

3

4

5

6

7

require 'libs/Smarty.class.php'; //包含Smarty类库文件

$smarty = new Smarty; //创建一个新的Smarty对象

$array1 = array(1 => "Simon", 2 => "Elaine", 3 => "Susan"); //定义数组

$smarty->assign("array1",$array1); //对模版中的变量赋值

$smarty->display('test3.htm'); //显示页面

?>

5 6

7

8

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Smarty Test

{section name=section1 loop=$array1}

{/section}

{$array1[section1]}

9 10

11

12

13

1

2

3

4

5

6

7

require 'libs/Smarty.class.php'; //包含Smarty类库文件

$smarty = new Smarty; //创建一个新的Smarty对象

$array1 = array(0 => "Simon", 1 => "Elaine", 2 => "Susan"); //定义数组

$smarty->assign("array1",$array1); //对模版中的变量赋值

$smarty->display('test10.htm'); //显示页面

?>

14 15
Smarty Test {foreach key=key1 item=item1 from=$array1} {/foreach}
{$key1} {$item1}
1 2 3 4 5 6 7 <🎜>require 'libs/Smarty.class.php'; //Contains Smarty class library files<🎜> <🎜>$smarty = new Smarty; //Create a new Smarty object<🎜> <🎜>$array1 = array(1 => "Simon", 2 => "Elaine", 3 => "Susan"); //Define array $smarty->assign("array1",$array1); //Assign values ​​to variables in the template $smarty->display('test3.htm'); //Display page ?>
Another method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Smarty Test {section name=section1 loop=$array1} {/section}
{$array1[section1]}
1 2 3 4 5 6 7 <🎜>require 'libs/Smarty.class.php'; //Contains Smarty class library files<🎜> <🎜>$smarty = new Smarty; //Create a new Smarty object<🎜> <🎜>$array1 = array(0 => "Simon", 1 => "Elaine", 2 => "Susan"); //Define array<🎜> <🎜>$smarty->assign("array1",$array1); //Assign values ​​to variables in the template $smarty->display('test10.htm'); //Display page ?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1015340.htmlTechArticleThe smart area loop method in php. This article describes the smart area loop method in php. Share it with everyone for your reference. The specific implementation method is as follows: 1 2 3 4 5 6 7 8 9 10 11 12 1...
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