Smarty Template engine Assignment data type, smarty template data type _php tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.