Smarty Template engine Assignment data type, smarty template data type
This article describes the allocation data type usage of the Smarty template engine. Share to everyone for your reference. The specific analysis is as follows:
I. Allocation of BASIC data
The browser displays the results:
1 means true, 0 means false, false is null, nothing is displayed.
Second, the allocation of composite data array
Indexed array $res =array (' Shanghai ', ' Beijing ', ' Shenzhen '), $smarty->assign ("arr", $res);//associative array $res2=array (' city1 ' + ' Beijing ', ' city2 ' = > ' guangzhou ', ' city3 ' = ' Hunan ', $smarty->assign ("arr2", $res 2); Indexed two-dimensional array $res3 = array ( ' Xiao Shan ', ' Changshan ', ' Wu Bei '), Array (' Shan Shan ', ' Keep your ')), $smarty->assign ("Arr3", $res 3);//Associative two-dimensional array $ res4 = Array ( ' id ' = ' = ' 001 ', ' name ' = ' = ' Zhang San ', ' email ' = ' zhangsan@1163.com '), array (' url ' = = ') Http://www.baidu.com ', ' age ' = ' 28 '); $smarty->assign ("Arr4", $res 4); Associative two-dimensional array 2 $res 5=array (' emp1 ' =>array (' id ' = ' 001 ', ' name ' = ' Zhang San ', ' email ' = ' zhangsan@1163.com '), ' emp2 ' =>array (' url ' = ' http://www.baidu.com ', ' age ' = ' 28 ')); $smarty->assign ("Arr5", $res 5);
Template file
Associative two-dimensional array form 2:id-<{$arr 5.emp1.id}>, name-<{$arr 5.emp1.name}>, email-<{$arr 5.emp1.email}>, url-<{ $arr 5.emp2.url}>, age-<{$arr 5.emp2.age}>
The browser displays the results:
Third, the allocation of composite data Objects
Class master{ var $name; var $age; function __construct ($name, $age) { $this->name= $name; $this->age= $age; } } class dog{var $name, var $age, var $color, var $arr, var $master, function __construct ($name, $age, $color, $arr 6, $master) { $this->name= $name; $this->age= $age; $this->color= $color; $this->arr= $arr 6; $this->master= $master; } } $arr 6=array (' 001 ', ' 002 ', ' 003 '); $master = new Master (' Xiao Ming ', 22); $dog 1 = new Dog (' Small white ', 1, ' Bai ', $arr 6, $master); $smarty->assign ("Dog", $dog 1);
Template file
Object:
Browser Display Results
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/976032.html www.bkjia.com true http://www.bkjia.com/PHPjc/976032.html techarticle smarty Template engine assignment data type, smarty template data Type This article describes the allocation data type usage of the Smarty template engine. Share to everyone for your reference. A specific analysis such as ...