{"id":57,"date":"2011-12-31T06:02:32","date_gmt":"2011-12-31T06:02:32","guid":{"rendered":"http:\/\/www.shuran.cn\/?p=57"},"modified":"2012-02-08T04:06:30","modified_gmt":"2012-02-08T04:06:30","slug":"smarty%e6%a8%a1%e6%9d%bf%e8%bf%9b%e9%98%b6%e6%95%99%e7%a8%8b%e4%b8%89","status":"publish","type":"post","link":"https:\/\/www.shuran.cn\/?p=57","title":{"rendered":"Smarty\u6a21\u677f\u8fdb\u9636\u6559\u7a0b(\u4e09)"},"content":{"rendered":"<p align=\"center\"><span style=\"color: #cc0000; font-size: xx-small;\"><strong>Smarty\u6a21\u677f\u8fdb\u9636\u6559\u7a0b(\u4e09)<\/strong><\/span><\/p>\n<p>\u524d\u9762\u6211\u4eec\u66fe\u7ecf\u7b80\u5355\u63d0\u53caSmarty\u7528\u4e8e\u5904\u7406\u5faa\u73af\u7684\u65b9\u6848\uff0dsection\uff0c\u540c\u65f6\u5728\u4e0a\u4e00\u7bc7\u7684\u5185\u5efa\u51fd\u6570\u5217\u8868\u4e2d\u5927\u5bb6\u5e94\u8be5\u4e5f\u770b\u5230\u4e86\u8fd8\u6709\u4e00\u4e2a\u5904\u7406\u5faa\u73af\u7684\u65b9\u6848\uff0dforeach\u3002\u8fd9\u6b21\u6211\u4eec\u5c31\u6765\u6bd4\u8f83\u4e00\u4e0b\u8fd9\u4e24\u4e2a\u65b9\u6848\u7684\u5f02\u540c\u70b9\u5e76\u8be6\u7ec6\u5206\u6790\u5b83\u4eec\u7684\u7528\u6cd5\u3002<\/p>\n<p>\u9996\u5148\u6211\u4eec\u6765\u770b\u4e00\u4e0b\u5b83\u4eec\u5728\u8bed\u6cd5\u4e0a\u7684\u5f02\u540c\uff1a<\/p>\n<table width=\"700\" cellspacing=\"0\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td><span style=\"color: #ff0000;\">\u811a\u672c\uff1a<\/span><br \/>\n$custid = array(1000,1001,1002);<br \/>\n$smarty-&gt;assign('custid',$custid);<\/p>\n<p><span style=\"color: #ff0000;\">foreach\u6a21\u677f\uff1a<\/span><br \/>\n{* \u8be5\u4f8b\u5c06\u8f93\u51fa\u6570\u7ec4 $custid \u4e2d\u7684\u6240\u6709\u5143\u7d20\u7684\u503c *}<br \/>\n{foreach from=$custid item=curr_id}<br \/>\n\u00a0\u00a0id: {$curr_id}&lt;br&gt;<br \/>\n{\/foreach}<\/p>\n<p><span style=\"color: #ff0000;\">section\u6a21\u677f\uff1a<\/span><br \/>\n{* \u8be5\u4f8b\u540c\u6837\u8f93\u51fa\u6570\u7ec4 $custid \u4e2d\u7684\u6240\u6709\u5143\u7d20\u7684\u503c *}<br \/>\n{section name=customer loop=$custid}<br \/>\n\u00a0\u00a0id: {$custid[customer]}&lt;br&gt;<br \/>\n{\/section}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>foreach\u7684\u8bed\u6cd5\u53ef\u4ee5\u6982\u62ec\u4e3a\uff1a\u5c06\u4e00\u4e2a\u6570\u7ec4assign\u7ed9from=\u540e\u9762\u7684\u53d8\u91cf\u540d\uff0c\u6570\u7ec4\u5143\u7d20\u4f1a\u4f9d\u6b21\u8d4b\u7ed9item=\u540e\u9762\u7684\u53d8\u91cf\u540d\uff0c\u8981\u663e\u793a\u5143\u7d20\u5219\u53ea\u9700\u8981\u8f93\u51faitem\u53d8\u91cf\u5373\u53ef\uff1b<br \/>\nsection\u7684\u8bed\u6cd5\u5219\u662f\uff1a\u5c06\u4e00\u4e2a\u6570\u7ec4assign\u7ed9loop=\u540e\u9762\u7684\u53d8\u91cf\u540d\uff0c\u7136\u540e\u7531name=\u540e\u9762\u7684\u53d8\u91cf\u540d\u6765\u4f5c\u4e3a\u4e00\u4e2a\u4e0b\u6807(\u6307\u9488)\uff0c\u8981\u663e\u793a\u5143\u7d20\u5219\u9700\u8981\u8f93\u51fa\u4e00\u4e2a\u6570\u7ec4\u5f62\u5f0f{$custid[customer]}\uff1b<\/p>\n<p>\u770b\u5230\u8fd9\u91cc\u4f30\u8ba1\u5927\u5bb6\u4f1a\u4ea7\u751f\u4e00\u4e2a\u7591\u60d1\uff0cforeach\u7b80\u5355\u660e\u4e86\uff0c\u5bb9\u6613\u7406\u89e3\uff0csection\u663e\u5f97\u5c31\u6709\u4e9b\u590d\u6742\uff0c\u4e3a\u4ec0\u4e48\u5462\uff1f\u6211\u4eec\u5148\u770b\u4e0b\u4e24\u8005\u7684\u8bf4\u660e\uff1a<\/p>\n<p>foreach \u7528\u4e8e\u5904\u7406\u7b80\u5355\u6570\u7ec4(\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u7684\u7c7b\u578b\u4e00\u81f4)\uff0c\u5b83\u7684\u683c\u5f0f\u6bd4 section \u7b80\u5355\u8bb8\u591a\uff0c\u7f3a\u70b9\u662f\u53ea\u80fd\u5904\u7406\u7b80\u5355\u6570\u7ec4\u3002<br \/>\nforeach \u5fc5\u987b\u548c \/foreach \u6210\u5bf9\u4f7f\u7528\uff0c\u4e14\u5fc5\u987b\u6307\u5b9a from \u548c item \u5c5e\u6027\u3002<br \/>\nname \u5c5e\u6027\u53ef\u4ee5\u4efb\u610f\u6307\u5b9a(\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\u7684\u7ec4\u5408)\u3002<br \/>\nforeach \u53ef\u4ee5\u5d4c\u5957\uff0c\u4f46\u5fc5\u987b\u4fdd\u8bc1\u5d4c\u5957\u4e2d\u7684 foreach \u540d\u79f0\u552f\u4e00\u3002<br \/>\nfrom \u5c5e\u6027(\u901a\u5e38\u662f\u6570\u7ec4)\u51b3\u5b9a\u5faa\u73af\u7684\u6b21\u6570\u3002<br \/>\nsection \u6807\u7b7e\u5fc5\u987b\u8bbe\u7f6e name \u548c loop \u5c5e\u6027\u3002<br \/>\n\u540d\u79f0\u53ef\u4ee5\u662f\u5305\u542b\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u4e0b\u5212\u7ebf\u7684\u4efb\u610f\u7ec4\u5408\u3002<br \/>\n\u53ef\u4ee5\u5d4c\u5957\u4f46\u5fc5\u987b\u4fdd\u8bc1\u5d4c\u5957\u7684 name \u552f\u4e00\u3002<br \/>\n\u53d8\u91cf loop (\u901a\u5e38\u662f\u6570\u7ec4)\u51b3\u5b9a\u5faa\u73af\u6267\u884c\u7684\u6b21\u6570\u3002<br \/>\n\u5f53\u9700\u8981\u5728 section \u5faa\u73af\u5185\u8f93\u51fa\u53d8\u91cf\u65f6\uff0c\u5fc5\u987b\u5728\u53d8\u91cf\u540e\u52a0\u4e0a\u4e2d\u62ec\u53f7\u5305\u542b\u7740\u7684 name \u53d8\u91cf\u3002<\/p>\n<p>\u901a\u8fc7\u6bd4\u8f83\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\uff0csection\u7684loop\u548cforeach\u7684from\u6bd4\u8f83\u8c61\uff1bsection\u7684name\u548cforeach\u7684item\u6bd4\u8f83\u8c61\uff0c\u4f3c\u4e4e\u533a\u522b\u4ec5\u5728\u4e8eforeach\u53ea\u80fd\u5904\u7406\u7b80\u5355\u6570\u7ec4\u8fd9\u4e00\u53e5\u3002\u90a3\u4e48\u6211\u4eec\u5c31\u6765\u6f14\u793a\u4e0b\u4ec0\u4e48\u60c5\u51b5\u662fforeach\u5904\u7406\u4e0d\u4e86\u7684\u3002<\/p>\n<p>\u5148\u770b\u4e00\u4e2a\u591a\u6570\u7ec4\u7684\u4f8b\u5b50\uff1a<\/p>\n<table width=\"700\" cellspacing=\"0\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td><span style=\"color: #ff0000;\">\u811a\u672c\uff1a<\/span><br \/>\n$custid = array(1000,1001,1002);<br \/>\n$name = array('john','jack','jane');<br \/>\n$smarty-&gt;assign('custid',$custid);<br \/>\n$smarty-&gt;assign('name',$name);<\/p>\n<p><span style=\"color: #ff0000;\">\u6a21\u677f\uff1a<\/span><br \/>\n{* \u8be5\u4f8b\u540c\u65f6\u6df7\u5408\u8f93\u51fa\u6570\u7ec4 $custid\u548c$name\u4e2d\u7684\u6240\u6709\u5143\u7d20\u7684\u503c *}<br \/>\n{section name=customer loop=$custid}<br \/>\n\u00a0\u00a0id: {$custid[customer]}&lt;br&gt;<br \/>\n\u00a0\u00a0name: {$name[customer]}&lt;br&gt;<br \/>\n{\/section}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u8fd9\u4e2a\u4f8b\u5b50\u663e\u793a\u4e86section\u7684name\u548cforeach\u7684item\u662f\u4e0d\u540c\u7684\uff0c\u8981\u60f3\u7528foreach\u83b7\u5f97\u540c\u6837\u7684\u6548\u679c\u5c31\u6ca1\u8fd9\u4e48\u65b9\u4fbf\u4e86\u3002<\/p>\n<p>\u5bf9\u4e8e\u591a\u7ef4\u6570\u7ec4\u7684\u5904\u7406\uff0c\u4e24\u8005\u5012\u662f\u6ca1\u4ec0\u4e48\u533a\u522b\uff1a<\/p>\n<table width=\"700\" cellspacing=\"0\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td><span style=\"color: #ff0000;\">\u811a\u672c\uff1a<\/span><br \/>\n$customer[] = array('custid'=&gt;1000,'name'=&gt;'john','address'=&gt;'253 N 45th');<br \/>\n$customer[] = array('custid'=&gt;1001,'name'=&gt;'jack','address'=&gt;'417 Mulberry ln');<br \/>\n$customer[] = array('custid'=&gt;1002,'name'=&gt;'jane','address'=&gt;'5605 apple st'); $smarty-&gt;assign('customer',$customer);<\/p>\n<p><span style=\"color: #ff0000;\">foreach \u6a21\u677f\uff1a<\/span><br \/>\n{foreach from=$customer item=curr_item}<br \/>\n\u00a0\u00a0id: {$curr_item.custid}&lt;br&gt;<br \/>\n\u00a0\u00a0name: {$curr_item.name}&lt;br&gt;<br \/>\n\u00a0\u00a0address: {$curr_item.address}&lt;br&gt;<br \/>\n&lt;p&gt;<br \/>\n{\/foreach}<\/p>\n<p><span style=\"color: #ff0000;\">section\u6a21\u677f\uff1a<\/span><br \/>\n{section name=cust loop=$customer}<br \/>\n\u00a0\u00a0id: {$customer[cust].custid}&lt;br&gt;<br \/>\n\u00a0\u00a0name: {$customer[cust].name}&lt;br&gt;<br \/>\n\u00a0\u00a0address: {$customer[cust].address}&lt;br&gt;<br \/>\n&lt;p&gt;<br \/>\n{\/section}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u663e\u793a\u7ed3\u679c\u662f\u4e00\u6837\u7684\u3002<\/p>\n<p>\u4e0b\u9762\u6765\u770b\u4e00\u4e0b\u5d4c\u5957\u7684\u60c5\u51b5\uff0c\u6211\u4eec\u4e3a\u4e0a\u4e00\u4f8b\u7684\u6570\u7ec4\u589e\u52a0\u4e00\u4e2acontact_type\uff0c\u503c\u4e3a\u4e00\u4e2a\u8054\u7cfb\u65b9\u5f0f\u7684\u6570\u7ec4\uff0c\u5728foreach\u4e2d\u5e94\u8be5\u5982\u4e0b\u5d4c\u5957\uff1a<\/p>\n<table width=\"700\" cellspacing=\"0\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td><span style=\"color: #ff0000;\">\u811a\u672c\uff1a<\/span><br \/>\n$customer[] = array('custid'=&gt;1000,'name'=&gt;'john','address'=&gt;'253 N 45th','contact_type'=&gt;<br \/>\narray('home phone'=&gt;'555-555-5555','cell phone'=&gt;'555-555-5555','e-mail'=&gt;'john@mydomain.com'));<br \/>\n$customer[] = array('custid'=&gt;1001,'name'=&gt;'jack','address'=&gt;'417 Mulberry ln','contact_type'=&gt;<br \/>\narray('home phone'=&gt;'444-444-4444','cell phone'=&gt;'444-444-4444','e-mail'=&gt;'jack@mydomain.com'));<br \/>\n$customer[] = array('custid'=&gt;1002,'name'=&gt;'jane','address'=&gt;'5605 apple st','contact_type'=&gt;<br \/>\narray('home phone'=&gt;'666-666-6666','cell phone'=&gt;'666-666-6666','e-mail'=&gt;'jane@mydomain.com'));<br \/>\n$smarty-&gt;assign('customer',$customer);<\/p>\n<p><span style=\"color: #ff0000;\">foreach \u6a21\u677f\uff1a<\/span><br \/>\n{foreach from=$customer item=curr_item}<br \/>\n\u00a0\u00a0id: {$curr_item.custid}&lt;br&gt;<br \/>\n\u00a0\u00a0name: {$curr_item.name}&lt;br&gt;<br \/>\n\u00a0\u00a0address: {$curr_item.address}&lt;br&gt;<br \/>\n\u00a0\u00a0{foreach from=$curr_item.contact_type item=contact key=key}<br \/>\n\u00a0\u00a0\u00a0\u00a0{$key}: {$contact}&lt;br&gt;<br \/>\n\u00a0\u00a0{\/foreach}<br \/>\n&lt;p&gt;<br \/>\n{\/foreach}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u663e\u793a\u7ed3\u679c\u5982\u4e0b\uff1a<br \/>\nid: 1000<br \/>\nname: john<br \/>\naddress: 253 N 45th<br \/>\nhome phone: 555-555-5555<br \/>\ncell phone: 555-555-5555<br \/>\ne-mail: john@mydomain.com<\/p>\n<p>id: 1001<br \/>\nname: jack<br \/>\naddress: 417 Mulberry ln<br \/>\nhome phone: 444-444-4444<br \/>\ncell phone: 444-444-4444<br \/>\ne-mail: jack@mydomain.com<\/p>\n<p>id: 1002<br \/>\nname: jane<br \/>\naddress: 5605 apple st<br \/>\nhome phone: 666-666-6666<br \/>\ncell phone: 666-666-6666<br \/>\ne-mail: jane@mydomain.com<br \/>\n\uff08\u672c\u4f8b\u4e2d\u6211\u4eec\u987a\u4fbf\u770b\u5230\u4e86key\u7684\u7528\u6cd5\uff0ckey\u5c31\u662f\u6bcf\u4e2a\u5faa\u73af\u7684\u5143\u7d20\u952e\u503c\uff09<\/p>\n<p>\u5728section\u4e2d\u7531\u4e8e\u4e66\u5199\u683c\u5f0f\u7684\u4e0d\u540c\uff0c\u811a\u672c\u6709\u4e9b\u5dee\u5f02\uff1a<\/p>\n<table width=\"700\" cellspacing=\"0\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td><span style=\"color: #ff0000;\">\u811a\u672c\uff1a<\/span><br \/>\n$customer[] = array('custid'=&gt;1000,'name'=&gt;'john','address'=&gt;'253 N 45th');<br \/>\n$customer[] = array('custid'=&gt;1001,'name'=&gt;'jack','address'=&gt;'417 Mulberry ln');<br \/>\n$customer[] = array('custid'=&gt;1002,'name'=&gt;'jane','address'=&gt;'5605 apple st');<br \/>\n$contact_type[] = array('home phone','cell phone','e-mail');<br \/>\n$contact_type[] = array('home phone','cell phone','e-mail');<br \/>\n$contact_type[] = array('home phone','cell phone','e-mail');<br \/>\n$contact_info[] = array('555-555-5555','555-555-5555','john@mydomain.com');<br \/>\n$contact_info[] = array('444-444-4444','444-444-4444','jack@mydomain.com');<br \/>\n$contact_info[] = array('666-666-6666','666-666-6666','jane@mydomain.com');<br \/>\n$smarty-&gt;assign('contact_type',$contact_type);<br \/>\n$smarty-&gt;assign('contact_info',$contact_info);<br \/>\n$smarty-&gt;assign('customer',$customer);<\/p>\n<p><span style=\"color: #ff0000;\">section \u6a21\u677f\uff1a<\/span><br \/>\n{section name=cust loop=$customer}<br \/>\n\u00a0\u00a0id: {$customer[cust].custid}&lt;br&gt;<br \/>\n\u00a0\u00a0name: {$customer[cust].name}&lt;br&gt;<br \/>\n\u00a0\u00a0address: {$customer[cust].address}&lt;br&gt;<br \/>\n\u00a0\u00a0{section name=contact loop=$contact_type[cust]}<br \/>\n\u00a0\u00a0\u00a0\u00a0{$contact_type[cust][contact]}: {$contact_info[cust][contact]}&lt;br&gt;<br \/>\n\u00a0\u00a0{\/section}<br \/>\n&lt;p&gt;<br \/>\n{\/section}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u663e\u793a\u7ed3\u679c\u548c\u4e0a\u9762\u7684foreach\u7ed3\u679c\u662f\u4e00\u6837\u7684\u3002<br \/>\n\u4e24\u79cd\u5d4c\u5957\u65b9\u5f0f\uff0c\u770b\u4e0a\u53bbsection\u7684\u7e41\u7410\u4e00\u4e9b\uff0cforeach\u7b80\u5355\u660e\u4e86\uff0c\u5176\u5b9e\u4e0d\u7136\uff0c\u5b8c\u5168\u662f\u56e0\u4e3a\u4e24\u8005\u6240\u4f7f\u7528\u7684\u6570\u636e\u7684\u683c\u5f0f\u4e0d\u540c\uff0c\u5982\u679c\u60a8\u80fd\u591f\u63a7\u5236\u6570\u636e\u7684\u683c\u5f0f\uff0c\u53ef\u4ee5\u5728\u4f7f\u7528\u65f6\u8003\u8651foreach\u4f8b\u5b50\u4e2d\u7684\u5f62\u5f0f\uff0c\u5982\u679c\u60a8\u53ea\u80fd\u5f97\u5230section\u4f8b\u5b50\u4e2d\u8fd9\u6837\u7684\u6570\u636e\u683c\u5f0f\uff0c\u90a3\u5c31\u53ea\u80fd\u4f7f\u7528section\u4f8b\u5b50\u7684\u5199\u6cd5\u4e86\u3002<\/p>\n<p>\u6700\u540e\u6211\u4eec\u6765\u4e86\u89e3\u4e00\u4e0b\u8fd9\u4e24\u4e2a\u5faa\u73af\u7684\u4e00\u4e9b\u53d8\u91cf\u3002<br \/>\nforeach \u5faa\u73af\u6709\u81ea\u5df1\u7684\u53d8\u91cf\u540d\uff0c\u4f7f\u7528\u8be5\u53d8\u91cf\u540d\u53ef\u4ee5\u8bbf\u95ee\u8be5\u5faa\u73af\u3002\u4f7f\u7528\u65b9\u6cd5\u4e3a{$smarty.foreach.foreachname.varname}\uff0c\u540c\u6837\uff0csection\u5c31\u7528{$smarty.section.sectionname.varname}\u3002\u4e0b\u9762\u6211\u4eec\u6765\u5bf9\u7167\u7740\u5b66\u4e60\u4e24\u8005\u7684\u53d8\u91cf\uff0c\u5148\u5b66\u4e24\u8005\u90fd\u6709\u7684\uff1a<br \/>\n0\u3001\u524d\u9762\u5df2\u7ecf\u63d0\u5230\u7684\u6709\uff1aname\u3001foreach\u7684from\u76f8\u5f53\u4e8esection\u7684loop\uff0c\u8fd9\u91cc\u5c31\u4e0d\u518d\u4ecb\u7ecd\u4e86\u3002<\/p>\n<p>1\u3001iteration \u7528\u4e8e\u663e\u793a\u5faa\u73af\u7684\u6b21\u6570\uff0c\u4ece1\u5f00\u59cb<\/p>\n<table width=\"700\" cellspacing=\"0\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td><span style=\"color: #ff0000;\">\u811a\u672c\uff1a<\/span><br \/>\n$customer[] = array('custid'=&gt;1000);<br \/>\n$customer[] = array('custid'=&gt;1001);<br \/>\n$customer[] = array('custid'=&gt;1002);<br \/>\n$smarty-&gt;assign('customer',$customer);<\/p>\n<p><span style=\"color: #ff0000;\">foreach \u6a21\u677f\uff1a<\/span><br \/>\n{foreach from=$customer item=curr_item name=cust}<br \/>\n\u00a0\u00a0id: {$curr_item.custid}&lt;br&gt;<br \/>\n\u00a0\u00a0current loop iteration: {$smarty.foreach.cust.iteration}&lt;br&gt;<br \/>\n\u00a0\u00a0&lt;p&gt;<br \/>\n{\/foreach}<br \/>\n<span style=\"color: #ff0000;\">section \u6a21\u677f\uff1a<\/span><br \/>\n{section name=cust loop=$customer}<br \/>\n\u00a0\u00a0id: {$customer[cust].custid}&lt;br&gt;<br \/>\n\u00a0\u00a0current loop iteration: {$smarty.section.cust.iteration}&lt;br&gt;<br \/>\n\u00a0\u00a0&lt;p&gt;<br \/>\n{\/section}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u770b\u4f8b\u5b50\uff0c\u4e24\u8005\u6ca1\u4ec0\u4e48\u533a\u522b\uff0c\u5c31\u662fforeach\u7684name\u4e0d\u662f\u5fc5\u9700\u7684\uff0c\u6240\u4ee5\u522b\u5fd8\u4e86\u8bbe\u5b9a\u3002<\/p>\n<p>2\u3001first \u5f53\u524d foreach \u6216 section \u5faa\u73af\u7b2c\u4e00\u6b21\u6267\u884c\u65f6 first \u88ab\u8bbe\u7f6e\u6210 true<\/p>\n<table width=\"700\" cellspacing=\"0\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td><span style=\"color: #ff0000;\">\u811a\u672c\uff1a<\/span><br \/>\n\u540c\u4e0a<\/p>\n<p><span style=\"color: #ff0000;\">foreach \u6a21\u677f\uff1a<\/span><br \/>\n{foreach from=$customer item=curr_item name=cust}<br \/>\n\u00a0\u00a0id: {$curr_item.custid}&lt;br&gt;<br \/>\n\u00a0\u00a0{if $smarty.foreach.cust.first}This is the first row{\/if}&lt;br&gt;<br \/>\n\u00a0\u00a0&lt;p&gt;<br \/>\n{\/foreach}<br \/>\n<span style=\"color: #ff0000;\">section \u6a21\u677f\uff1a<\/span><br \/>\n{section name=cust loop=$customer}<br \/>\n\u00a0\u00a0id: {$customer[cust].custid}&lt;br&gt;<br \/>\n\u00a0\u00a0{if $smarty.section.cust.first}This is the first row{\/if}&lt;br&gt;<br \/>\n\u00a0\u00a0&lt;p&gt;<br \/>\n{\/section}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u663e\u793a\u7ed3\u679c\u5728\u7b2c\u4e00\u4e2a\u5143\u7d20\u884c\u4f1a\u591a\u8f93\u51faThis is the first row\uff0c\u5176\u4f59\u884c\u5c31\u4e0d\u4f1a\u3002<\/p>\n<p>3\u3001last \u5f53\u524d foreach \u6216 section \u5faa\u73af\u6267\u884c\u5230\u6700\u540e\u4e00\u904d\u65f6 last \u88ab\u8bbe\u7f6e\u6210 true<\/p>\n<table width=\"700\" cellspacing=\"0\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td><span style=\"color: #ff0000;\">\u811a\u672c\uff1a<\/span><br \/>\n\u540c\u4e0a<\/p>\n<p><span style=\"color: #ff0000;\">foreach \u6a21\u677f\uff1a<\/span><br \/>\n{foreach from=$customer item=curr_item name=cust}<br \/>\n\u00a0\u00a0id: {$curr_item.custid}&lt;br&gt;<br \/>\n\u00a0\u00a0{if $smarty.foreach.cust.last}This is the last row{\/if}&lt;br&gt;<br \/>\n\u00a0\u00a0&lt;p&gt;<br \/>\n{\/foreach}<br \/>\n<span style=\"color: #ff0000;\">section \u6a21\u677f\uff1a<\/span><br \/>\n{section name=cust loop=$customer}<br \/>\n\u00a0\u00a0id: {$customer[cust].custid}&lt;br&gt;<br \/>\n\u00a0\u00a0{if $smarty.section.cust.last}This is the last row{\/if}&lt;br&gt;<br \/>\n\u00a0\u00a0&lt;p&gt;<br \/>\n{\/section}<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>4\u3001show \u8be5\u5faa\u73af\u662f\u5426\u663e\u793a\uff0cshow \u53d6\u503c\u4e3a\u5e03\u5c14\u503c true \u6216 false\u3002\u5982\u679c\u8bbe\u7f6e\u4e3a false\uff0c\u8be5\u5faa\u73af\u5c06\u4e0d\u663e\u793a\u3002\u5982\u679c\u6307\u5b9a\u4e86foreachelse\u6216 sectionelse \u5b50\u53e5\uff0c\u8be5\u5b57\u53e5\u662f\u5426\u663e\u793a\u4e5f\u53d6\u51b3\u4e8e\u8be5\u503c<\/p>\n<p>5\u3001total \u7528\u4e8e\u663e\u793a\u5faa\u73af\u6267\u884c\u7684\u6b21\u6570\uff0c\u53ef\u4ee5\u5728\u5faa\u73af\u4e2d\u6216\u5faa\u73af\u6267\u884c\u540e\u8c03\u7528<\/p>\n<table width=\"700\" cellspacing=\"0\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td><span style=\"color: #ff0000;\">\u811a\u672c\uff1a<\/span><br \/>\n\u540c\u4e0a<\/p>\n<p><span style=\"color: #ff0000;\">foreach \u6a21\u677f\uff1a<\/span><br \/>\n{foreach from=$customer item=curr_item name=cust}<br \/>\n\u00a0\u00a0id: {$curr_item.custid}&lt;br&gt;<br \/>\n\u00a0\u00a0{$smarty.foreach.cust.total}&lt;br&gt;<br \/>\n\u00a0\u00a0&lt;p&gt;<br \/>\n{\/foreach}<br \/>\n{$smarty.foreach.cust.total}&lt;br&gt;<br \/>\n<span style=\"color: #ff0000;\">section \u6a21\u677f\uff1a<\/span><br \/>\n{section name=cust loop=$customer}<br \/>\n\u00a0\u00a0id: {$customer[cust].custid}&lt;br&gt;<br \/>\n\u00a0\u00a0{$smarty.section.cust.total}&lt;br&gt;<br \/>\n\u00a0\u00a0&lt;p&gt;<br \/>\n{\/section}<br \/>\n{$smarty.section.cust.total}&lt;br&gt;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5171\u6709\u7684\u53c2\u6570\u5c31\u662f\u8fd9\u4e9b\uff0c\u4e0b\u9762\u662fforeach\u72ec\u6709\u7684\u4e24\u4e2a\u53c2\u6570\uff1a<br \/>\n1\u3001item \u5f53\u524d\u5904\u7406\u5143\u7d20\u7684\u53d8\u91cf\u540d\u79f0<br \/>\n2\u3001key \u5f53\u524d\u5904\u7406\u5143\u7d20\u7684\u952e\u540d<br \/>\n\u524d\u6587\u5df2\u6709\u4ecb\u7ecd\uff0c\u4e0d\u518d\u8d58\u8ff0\u3002<\/p>\n<p>\u4e0b\u9762\u662fsection\u72ec\u6709\u7684\u53c2\u6570\uff1a<br \/>\n1\u3001index \u7528\u4e8e\u663e\u793a\u5f53\u524d\u5faa\u73af\u7684\u7d22\u5f15\uff0c\u4ece0\u5f00\u59cb(\u5982\u679c\u6307\u5b9a\u4e86start\u5c5e\u6027\uff0c\u90a3\u4e48\u7531\u8be5\u503c\u5f00\u59cb)\uff0c\u6bcf\u6b21\u52a01(\u5982\u679c\u6307\u5b9a\u4e86step\u5c5e\u6027\uff0c\u90a3\u4e48\u7531\u8be5\u503c\u51b3\u5b9a)\u3002<\/p>\n<table width=\"700\" cellspacing=\"0\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td><span style=\"color: #ff0000;\">\u811a\u672c\uff1a<\/span><br \/>\n\u540c\u4e0a<\/p>\n<p><span style=\"color: #ff0000;\">section \u6a21\u677f\uff1a<\/span><br \/>\n{section name=cust loop=$customer}<br \/>\n\u00a0\u00a0{$smarty.section.cust.index} id: {$customer[cust].custid}&lt;br&gt;<br \/>\n\u00a0\u00a0&lt;p&gt;<br \/>\n{\/section}<\/p>\n<p><span style=\"color: #ff0000;\">\u663e\u793a\u7ed3\u679c\uff1a<\/span><br \/>\n0 id: 10001 id: 1001<\/p>\n<p>2 id: 1002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>2\u3001index_prev \u7528\u4e8e\u663e\u793a\u4e0a\u4e00\u4e2a\u5faa\u73af\u7d22\u5f15\u503c\u3002\u5faa\u73af\u5f00\u59cb\u65f6\uff0c\u6b64\u503c\u4e3a-1\u3002<\/p>\n<table width=\"700\" cellspacing=\"0\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td><span style=\"color: #ff0000;\">\u811a\u672c\uff1a<\/span><br \/>\n\u540c\u4e0a<\/p>\n<p><span style=\"color: #ff0000;\">section \u6a21\u677f\uff1a<\/span><br \/>\n{section name=cust loop=$customer}<br \/>\n\u00a0\u00a0{$smarty.section.cust.index_prev} id: {$customer[cust].custid}&lt;br&gt;<br \/>\n\u00a0\u00a0&lt;p&gt;<br \/>\n{\/section}<\/p>\n<p><span style=\"color: #ff0000;\">\u663e\u793a\u7ed3\u679c\uff1a<\/span><br \/>\n-1 id: 10000 id: 1001<\/p>\n<p>1 id: 1002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>3\u3001index_next \u7528\u4e8e\u663e\u793a\u4e0b\u4e00\u4e2a\u5faa\u73af\u7d22\u5f15\u503c\u3002\u5faa\u73af\u6267\u884c\u5230\u6700\u540e\u4e00\u6b21\u65f6\uff0c\u6b64\u503c\u4ecd\u7136\u6bd4\u5f53\u524d\u7d22\u5f15\u503c\u59271(\u5982\u679c\u6307\u5b9a\u4e86step\uff0c\u53d6\u51b3\u4e8e\u6b64\u503c)\u3002<\/p>\n<table width=\"700\" cellspacing=\"0\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td><span style=\"color: #ff0000;\">\u811a\u672c\uff1a<\/span><br \/>\n\u540c\u4e0a<\/p>\n<p><span style=\"color: #ff0000;\">section \u6a21\u677f\uff1a<\/span><br \/>\n{section name=cust loop=$customer}<br \/>\n\u00a0\u00a0{$smarty.section.cust.index_next} id: {$customer[cust].custid}&lt;br&gt;<br \/>\n\u00a0\u00a0&lt;p&gt;<br \/>\n{\/section}<\/p>\n<p><span style=\"color: #ff0000;\">\u663e\u793a\u7ed3\u679c\uff1a<\/span><br \/>\n1 id: 10002 id: 1001<\/p>\n<p>3 id: 1002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>4\u3001rownum \u7528\u4e8e\u663e\u793a\u5faa\u73af\u7684\u6b21\u6570\u3002\u8be5\u5c5e\u6027\u662fiteration\u7684\u522b\u540d\uff0c\u4e24\u8005\u7b49\u540c\u3002<\/p>\n<p>5\u3001loop \u7528\u4e8e\u663e\u793a\u8be5\u5faa\u73af\u6700\u540e\u7684\u7d22\u5f15\u503c\u3002\u8be5\u503c\u53ef\u4ee5\u7528\u4e8e\u5faa\u73af\u5185\u90e8\u6216\u5faa\u73af\u7ed3\u675f\u540e\u3002\u5982\u679c\u672a\u8bbe\u7f6estart\u548cstep\uff0c\u5219\u548ctotal\u503c\u76f8\u7b49\u3002<\/p>\n<table width=\"700\" cellspacing=\"0\" cellpadding=\"10\">\n<tbody>\n<tr>\n<td><span style=\"color: #ff0000;\">\u811a\u672c\uff1a<\/span><br \/>\n\u540c\u4e0a<\/p>\n<p><span style=\"color: #ff0000;\">section \u6a21\u677f\uff1a<\/span><br \/>\n{section name=cust loop=$customer step=2}<br \/>\n\u00a0\u00a0{$smarty.section.cust.loop} id: {$customer[cust].custid}&lt;br&gt;<br \/>\n\u00a0\u00a0&lt;p&gt;<br \/>\n{\/section}<br \/>\n{$smarty.section.cust.total}<\/p>\n<p><span style=\"color: #ff0000;\">\u663e\u793a\u7ed3\u679c\uff1a<\/span><br \/>\n3 id: 10003 id: 1002<\/p>\n<p>2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>6\u3001start \u5faa\u73af\u6267\u884c\u7684\u521d\u59cb\u4f4d\u7f6e\u3002\u5982\u679c\u8be5\u503c\u4e3a\u8d1f\u6570\uff0c\u5f00\u59cb\u4f4d\u7f6e\u4ece\u6570\u7ec4\u7684\u5c3e\u90e8\u7b97\u8d77\u3002\u4f8b\u5982\uff1a\u5982\u679c\u6570\u7ec4\u4e2d\u67097\u4e2a\u5143\u7d20\uff0c\u6307\u5b9astart\u4e3a-2\uff0c\u90a3\u4e48\u6307\u5411\u5f53\u524d\u6570\u7ec4\u7684\u7d22\u5f15\u4e3a5<\/p>\n<p>7\u3001step \u8be5\u503c\u51b3\u5b9a\u5faa\u73af\u7684\u6b65\u957f\u3002\u4f8b\u5982\u6307\u5b9astep=2\u5c06\u53ea\u904d\u5386\u4e0b\u6807\u4e3a0\u30012\u30014\u7b49\u7684\u5143\u7d20\u3002\u5982\u679cstep\u4e3a\u8d1f\u503c\uff0c\u90a3\u4e48\u904d\u5386\u6570\u7ec4\u7684\u65f6\u5019\u4ece\u540e\u5411\u524d\u904d\u5386\u3002<\/p>\n<p>8\u3001max \u8bbe\u5b9a\u5faa\u73af\u6700\u591a\u6267\u884c\u51e0\u6b21\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Smarty\u6a21\u677f\u8fdb\u9636\u6559\u7a0b(\u4e09) \u524d\u9762\u6211\u4eec\u66fe\u7ecf\u7b80\u5355\u63d0\u53caSmarty\u7528\u4e8e\u5904\u7406\u5faa\u73af\u7684\u65b9\u6848\uff0dsection\uff0c\u540c\u65f6\u5728\u4e0a\u4e00\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.shuran.cn\/?p=57\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-57","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/posts\/57","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=57"}],"version-history":[{"count":3,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/posts\/57\/revisions"}],"predecessor-version":[{"id":59,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=\/wp\/v2\/posts\/57\/revisions\/59"}],"wp:attachment":[{"href":"https:\/\/www.shuran.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shuran.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}