【smarty】

WBOY
Release: 2016-06-23 14:12:06
Original
846 people have browsed it

Smarty

查询出来一个多维数组,不知道数组里面有什么元素,也不知道表结构,怎么输出呢?

通常的section 循环,不都是知道这个多维数组的字段才能显示出来结果啊

但是没有字段,该怎么显示呢?

回复讨论(解决方案)

有木有人啊!!!!!!!!

foreach 就可以啊
$smarty->assign("contacts", array(array("phone" => "1", "fax" => "2", "cell" => "3"),
 array("phone" => "555-4444", "fax" => "555-3333", "cell" => "760-1234")));
*}
{* 键就是数组的下标,请参看关于数组的解释 *}

{foreach name=outer item=contact from=$contacts}
 {foreach key=key item=item from=$contact}
 {$key}: {$item}

 {/foreach}
{/foreach}

输出结果:

phone: 1

fax: 2

cell: 3

phone: 555-4444

fax: 555-3333

cell: 760-1234

直接在php文件里面输出啊

不知道数组?用print_r()不就行了。

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