<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                <table summary="Header navigation table" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><th colspan="3" align="center">Smarty - the compiling PHP template engine</th></tr><tr><td width="25%" align="left" valign="bottom"><a href="language.function.php.html" accesskey="P">Prev</a></td> <td width="50%" align="center" valign="bottom">Chapter 7. Built-in Functions[第七章.內建函數]</td> <td width="25%" align="right" valign="bottom"><a href="language.function.while.html" accesskey="N">Next</a></td></tr></table> # {section},{sectionelse}遍歷數組 **Table of Contents目錄**[.index](#)[.index_prev](#)[.index_next](#)[.iteration](#)[.first](#)[.last](#)[.rownum](#)[.loop](#)[.show](#)[.total](#) A {section} is for looping over sequentially indexed arrays of data, unlike {foreach} which is used to loop over a single associative array. Every {section} tag must be paired with a closing {/section} tag. 不同于{foreach}遍歷單層關聯數組,{section}支持循序索引遍歷數組中的數據(支持一次性讀取多維數組)。每個{section}標簽必須與閉合標簽{/section}成對出現。 <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/> The {foreach} loop can do everything a {section} loop can do, and has a simpler and easier syntax. It is usually preferred over the {section} loop.<br/> {foreach}可以做{section}能做的所有事,而且語法更簡單、更容易。它通常是循環數組的首選。</td> </tr></table> <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/> {section} loops cannot loop over associative arrays, they must be numerically indexed, and sequential (0,1,2,...). For associative arrays, use the {foreach} loop. <br/> {section}循環不能遍歷關聯數組,(被循環的)數組必須是數字索引,像這樣(0,1,2,...)。對于關聯數組,請用{foreach}循環。</td> </tr></table> **Attribute:** | Attribute Name | Type | Required | Default | Description | |-----|-----|-----|-----|-----| | name | string | Yes | *n/a* | The name of the section | | loop | [$variable_name] | Yes | *n/a* | The name of the variable to determine # of loop iterations | | start | integer | No | *0* | The index position that the section will begin looping. If the value is negative, the start position is calculated from the end of the array. For example, if there are seven values in the loop array and start is -2, the start index is 5. Invalid values (values outside of the length of the loop array) are automatically truncated to the closest valid value. | | step | integer | No | *1* | The step value that will be used to traverse the loop array. For example, step=2 will loop on index 0,2,4, etc. If step is negative, it will step through the array backwards. | | max | integer | No | *1* | Sets the maximum number of times the section will loop. | | show | boolean | No | *true* | determines whether or not to show this section | **Option Flags:** | **Name** | **Description** | |-----|-----| | nocache | Disables caching of the {section} loop | **屬性:** | 屬性 | 類型 | 是否必須 | 缺省值 | 描述 | |-----|-----|-----|-----|-----| | name | string | Yes | *n/a* | 該循環的名稱 | | loop | [$variable_name] | Yes | *n/a* | 決定循環次數的變量名稱 | | start | integer | No | *0* | 循環執行的初始位置. 如果該值為負數,開始位置從數組的尾部算起. 例如:如果數組中有7個元素,指定start為-2,那么指向當前數組的索引為5. 非法值(超過了循環數組的下限)將被自動調整為最接近的合法值. | | step | integer | No | *1* | 該值決定循環的步長. 例如指定step=2將只遍歷下標為0、2、4等的元素. 如果step為負值,那么遍歷數組的時候從后向前遍歷. | | max | integer | No | *1* | 設定循環最大執行次數. | | show | boolean | No | *true* | 決定是否顯示該循環. | **選項標記:** | **名稱** | **描述** | |-----|-----| | nocache | {section} 循環禁用緩存 | * Required attributes are name and loop. * The name of the {section} can be anything you like, made up of letters, numbers and underscores,like PHP variables [http://php.net/language.variables]. * {section}'s can be nested, and the nested {section} names must be unique from each other. * The loop attribute, usually an array of values, determines the number of times the {section} will loop. You can also pass an integer as the loop value. * When printing a variable within a {section}, the {section} name must be given next to variable name within [brackets]. * {sectionelse} is executed when there are no values in the loop variable. * A {section} also has its own variables that handle {section} properties. These properties are accessible as: {$smarty.section.name.property} where “name” is the attribute name. * {section} properties are index, index_prev, index_next, iteration, first, last,rownum, loop, show, total. 必須設置*name*和*loop*屬性; {section}的名稱可以是你喜歡的任何字母、下劃線、數字組合,與php變量(命名)相同; {section}可以嵌套,但必須確保嵌套的{section}名稱唯一; *loop*屬性通常是一個數組值,它決定{section}循環的次數。你也可以為loop提供一個具體的整數值; 當需要在{section}內輸出一個變量時,{section}的變量名必須用方括號括起并挨在該輸出變量名的右邊(譯注:如$abc[mysection]); 當循環變量無值時執行{sectionelse}; {section}同樣有自己的變量處理{section}屬性,可以通過調用{$smarty.section.name.property}訪問這些屬性,這里‘name’是個變量名; {section}的屬性有index、index_prev、index_next、iteration、first、last、rownum、loop、show、total。 <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"><a name="AEN2760" id="AEN2760"/> <b><span class="PROGRAMLISTING">Example 7.60. Looping a simple array with {section}</span><br/> 例 7-60. 一個簡單{section}循環演示 </b> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><pre class="PROGRAMLISTING">assign() an array to Smarty&lt;?php$data = array(1000,1001,1002);$smarty-&gt;assign('custid',$data);?&gt;&#13; &#13; &#13; The template that outputs the array{* this example will print out all the values of the $custid array *}{section name=customer loop=$custid}{section customer $custid} {* short-hand *} id: {$custid[customer]}&lt;br /&gt;{/section}&lt;hr /&gt;{* print out all the values of the $custid array reversed *}反向輸出{section name=foo loop=$custid step=-1}{section foo $custid step=-1} {* short-hand *} {$custid[foo]}&lt;br /&gt;{/section}&#13; &#13; &#13; The above example will output:id: 1000&lt;br /&gt;id: 1001&lt;br /&gt;id: 1002&lt;br /&gt;&lt;hr /&gt;id: 1002&lt;br /&gt;id: 1001&lt;br /&gt;id: 1000&lt;br /&gt;</pre></td></tr></table></div></td></tr></table> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"> <p><b>Example 7.61. {section} without an assigned array<br/> 例 7-61.未分配數組的{section}演示 </b></p> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> {section name=foo start=10 loop=20 step=2}<br/>{$smarty.section.foo.index}<br/>{/section}<br/>&lt;hr /&gt;<br/>{section name=bar loop=21 max=6 step=-2}<br/>{$smarty.section.bar.index}<br/>{/section}<br/>The above example will output:<br/><br/>10 12 14 16 18<br/>&lt;hr /&gt;<br/>20 18 16 14 12 10</td></tr></table></div></td></tr></table> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"> <p><b>Example 7.62. Naming a {section}<br/> 例 7-62. {section}名稱演示</b></p> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> The name of the {section} can be anything you like, see PHP variables [http://php.net/ language.variables]. It is used to reference the data within the {section}.<br/> {section name=anything loop=$myArray}<br/>{$myArray[anything].foo}<br/>{$name[anything]}<br/>{$address[anything].bar}<br/>{/section}</td></tr></table></div></td></tr></table> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"> <p><b>Example 7.63. Looping an associative array with {section}<br/> 例 7-63. 用{section}循環關聯數組的演示</b></p> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> <p>This is an example of printing an associative array of data with a {section}. Following is the php script to assign the $contacts array to Smarty.<br/><br/> &lt;?php<br/> $data = array(<br/> array('name' =&gt; 'John Smith', 'home' =&gt; '555-555-5555',<br/> 'cell' =&gt; '666-555-5555', 'email' =&gt; 'john@myexample.com'),<br/> array('name' =&gt; 'Jack Jones', 'home' =&gt; '777-555-5555',<br/> 'cell' =&gt; '888-555-5555', 'email' =&gt; 'jack@myexample.com'),<br/> array('name' =&gt; 'Jane Munson', 'home' =&gt; '000-555-5555',<br/> 'cell' =&gt; '123456', 'email' =&gt; 'jane@myexample.com')<br/> );<br/> $smarty-&gt;assign('contacts',$data);<br/> ?&gt;<br/><br/> The template to output $contacts<br/> {section name=customer loop=$contacts}<br/> &lt;p&gt;<br/> name: {$contacts[customer].name}&lt;br /&gt;<br/> home: {$contacts[customer].home}&lt;br /&gt;<br/> cell: {$contacts[customer].cell}&lt;br /&gt;<br/> e-mail: {$contacts[customer].email}<br/> &lt;/p&gt;<br/> {/section}</p> <p> <br/> The above example will output:<br/> &lt;p&gt;<br/>name: John Smith&lt;br /&gt;<br/>home: 555-555-5555&lt;br /&gt;<br/>cell: 666-555-5555&lt;br /&gt;<br/>e-mail: john@myexample.com<br/>&lt;/p&gt;<br/>&lt;p&gt;<br/>name: Jack Jones&lt;br /&gt;<br/>home phone: 777-555-5555&lt;br /&gt;<br/>cell phone: 888-555-5555&lt;br /&gt;<br/>e-mail: jack@myexample.com<br/>&lt;/p&gt;<br/>&lt;p&gt;<br/>name: Jane Munson&lt;br /&gt;<br/>home phone: 000-555-5555&lt;br /&gt;<br/>cell phone: 123456&lt;br /&gt;<br/>e-mail: jane@myexample.com<br/>&lt;/p&gt;</p></td></tr></table></div></td></tr></table> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"> <p><b>Example 7.64. {section} demonstrating the loop variable<br/> 例 7-64. 演示{section}循環變量</b></p> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> <p>This example assumes假設 that $custid, $name and $address are all arrays containing the same number個數 of values. First the php script that assign's the arrays to Smarty.<br/> &lt;?php<br/> $id = array(1001,1002,1003);<br/> $smarty-&gt;assign('custid',$id);<br/> $fullnames = array('John Smith','Jack Jones','Jane Munson');<br/> $smarty-&gt;assign('name',$fullnames);<br/> $addr = array('253 Abbey road', '417 Mulberry ln', '5605 apple st');<br/> $smarty-&gt;assign('address',$addr);<br/> ?&gt;<br/> The loop variable only determines the number of times to loop. You can access ANY variable from the template within the {section}. This is useful for looping multiple arrays. You can pass an array which will determine the loop count by the array size, or you can pass an integer to specify the number of loops.</p> <p>loop變量只決定循環的次數,你可以訪問模版{section}中的任何變量,這個特性在多維數組中非常有用。你可以傳遞一個數組,該數組的大小決定循環間隔,或者您也可以通過一個整數來指定循環次數。</p> <p>{section name=customer loop=$custid}<br/> &lt;p&gt;<br/>id: {$custid[customer]}&lt;br /&gt;<br/>name: {$name[customer]}&lt;br /&gt;<br/>address: {$address[customer]}<br/>&lt;/p&gt;<br/>{/section}<br/><br/>The above example will output:<br/>&lt;p&gt;<br/>id: 1000&lt;br /&gt;<br/>name: John Smith&lt;br /&gt;<br/>address: 253 Abbey road<br/>&lt;/p&gt;<br/>&lt;p&gt;<br/>id: 1001&lt;br /&gt;<br/>name: Jack Jones&lt;br /&gt;<br/>address: 417 Mulberry ln<br/>&lt;/p&gt;<br/>&lt;p&gt;<br/>id: 1002&lt;br /&gt;<br/>name: Jane Munson&lt;br /&gt;<br/>address: 5605 apple st<br/>&lt;/p&gt;</p></td></tr></table></div></td></tr></table> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="EXAMPLE"><tr><td><div class="EXAMPLE"> <p><b>Example 7.65. Nested {section}'s<br/> 例 7-65. {section}嵌套 演示</b></p> <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> <p>{section}'s can be nested as deep as you like. With nested {section}'s, you can access complex data structures, such as multi-dimensional arrays. This is an example .php script thats assign's the arrays.</p> <p>{section}可以無限嵌套,在嵌套{section}里,你可以訪問復雜的數據結構,如多維數組。<br/> &lt;?php<br/> $id = array(1001,1002,1003);<br/> $smarty-&gt;assign('custid',$id);<br/> $fullnames = array('John Smith','Jack Jones','Jane Munson');<br/> $smarty-&gt;assign('name',$fullnames);<br/> $addr = array('253 N 45th', '417 Mulberry ln', '5605 apple st');<br/> $smarty-&gt;assign('address',$addr);<br/> $types = array(<br/> array( 'home phone', 'cell phone', 'e-mail'),<br/> array( 'home phone', 'web'),<br/> array( 'cell phone')<br/> );<br/> $smarty-&gt;assign('contact_type', $types);<br/> $info = array(<br/> array('555-555-5555', '666-555-5555', 'john@myexample.com'),<br/> array( '123-456-4', 'www.example.com'),<br/> array( '0457878')<br/> );<br/> $smarty-&gt;assign('contact_info', $info);<br/> ?&gt;<br/><br/> In this template, $contact_type[customer] is an array of contact types for the current customer.<br/> 在這個例子里面,$contact_type[customer]是當前customer的連聯類型數組。<br/><br/> {section name=customer loop=$custid}<br/> &lt;hr&gt;<br/> id: {$custid[customer]}&lt;br /&gt;<br/> name: {$name[customer]}&lt;br /&gt;<br/> address: {$address[customer]}&lt;br /&gt;<br/> {section name=contact loop=$contact_type[customer]}<br/> {$contact_type[customer][contact]}: {$contact_info[customer][contact]}&lt;br /&gt;<br/> {/section}<br/> {/section}<br/><br/> The above example will output:<br/> &lt;hr&gt;<br/> id: 1000&lt;br /&gt;<br/> name: John Smith&lt;br /&gt;<br/> address: 253 N 45th&lt;br /&gt;<br/> home phone: 555-555-5555&lt;br /&gt;<br/> cell phone: 666-555-5555&lt;br /&gt;<br/> e-mail: john@myexample.com&lt;br /&gt;<br/> &lt;hr&gt;<br/> id: 1001&lt;br /&gt;<br/> name: Jack Jones&lt;br /&gt;<br/> address: 417 Mulberry ln&lt;br /&gt;<br/> home phone: 123-456-4&lt;br /&gt;<br/> web: www.example.com&lt;br /&gt;<br/> &lt;hr&gt;<br/> id: 1002&lt;br /&gt;<br/> name: Jane Munson&lt;br /&gt;<br/> address: 5605 apple st&lt;br /&gt;<br/> cell phone: 0457878&lt;br /&gt; </p> </td></tr></table></div></td></tr></table> **Example 7.66. Database example with a {sectionelse} 例 7-66. {sectionelse}數據庫演示** <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> Results of a database search (eg ADODB or PEAR) are assigned to Smarty<br/><br/> &lt;?php<br/> $sql = 'select id, name, home, cell, email from contacts '<br/>."where name like '$foo%' ";<br/>$smarty-&gt;assign('contacts', $db-&gt;getAll($sql));<br/>?&gt;<br/>The template to output the database result in a HTML table<br/>&lt;table&gt;<br/>&lt;tr&gt;&lt;th&gt;&amp;nbsp;&lt;/th&gt;&lt;th&gt;Name&gt;&lt;/th&gt;&lt;th&gt;Home&lt;/th&gt;&lt;th&gt;Cell&lt;/th&gt;&lt;th&gt;Email&lt;/th&gt;&lt;/tr&gt;<br/>{section name=co loop=$contacts}<br/>&lt;tr&gt;<br/>&lt;td&gt;&lt;a href="view.php?id={$contacts[co].id}"&gt;view&lt;a&gt;&lt;/td&gt;<br/>&lt;td&gt;{$contacts[co].name}&lt;/td&gt;<br/>&lt;td&gt;{$contacts[co].home}&lt;/td&gt;<br/>&lt;td&gt;{$contacts[co].cell}&lt;/td&gt;<br/>&lt;td&gt;{$contacts[co].email}&lt;/td&gt;<br/>&lt;tr&gt;<br/>{sectionelse}<br/>&lt;tr&gt;&lt;td colspan="5"&gt;No items found&lt;/td&gt;&lt;/tr&gt;<br/>{/section}<br/>&lt;/table&gt;</td> </tr></table> .index index contains the current array index, starting with zero or the start attribute if given. It increments by one or by the step attribute if given. index包含當前數組的索引,以0開始,如果設置了start變量(屬性)則以該數字開始。{section}循環一次索引自動向前1步,如果給出了step變量則以該步長向前。 <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/>If the step and start properties are not modified, then this works the same as the iteration property, except it starts at zero instead of one.<br/>如果沒有修改step和start變量,則效果與iteration屬性(見下文的<a href="#iteration">.iteration</a>)一樣,除非后者以1開始,而不是0。</td> </tr></table> **Example 7.67. {section} index property 例 7-67. {section}的index屬性(變量)演示** <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> Note<br/> $custid[customer.index] and $custid[customer] are identical相同的.<br/> {section name=customer loop=$custid}<br/>{$smarty.section.customer.index} id: {$custid[customer]}&lt;br /&gt;<br/>{/section}<br/><br/>The above example will output:<br/>0 id: 1000&lt;br /&gt;<br/>1 id: 1001&lt;br /&gt;<br/>2 id: 1002&lt;br /&gt;</td> </tr></table> .index_prev index_prev is the previous loop index. On the first loop, this is set to -1. index_prev為前一循環的索引值。 循環開始時,此值為-1。 .index_next index_next is the next loop index. On the last loop, this is still one more than the current index,respecting the setting of the step attribute, if given. index_next為下個循環的索引值。循環到最尾,此值仍然比當前索引值大1,如果設定了step,取決于該值。 **Example 7.68. index, index_next and index_prev properties 例 7-68. index、index_next和index_prev屬性演示** <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><p>&lt;?php<br/> $data = array(1001,1002,1003,1004,1005);<br/> $smarty-&gt;assign('rows',$data);<br/> ?&gt;<br/> Template to output the above array in a table<br/> {* $rows[row.index] and $rows[row] are identical in meaning *}<br/> &lt;table&gt;<br/> &lt;tr&gt;<br/> &lt;th&gt;index&lt;/th&gt;&lt;th&gt;id&lt;/th&gt;<br/> &lt;th&gt;index_prev&lt;/th&gt;&lt;th&gt;prev_id&lt;/th&gt;<br/> &lt;th&gt;index_next&lt;/th&gt;&lt;th&gt;next_id&lt;/th&gt;<br/> &lt;/tr&gt;<br/> {section name=row loop=$rows}<br/> &lt;tr&gt;<br/> &lt;td&gt;{$smarty.section.row.index}&lt;/td&gt;&lt;td&gt;{$rows[row]}&lt;/td&gt;<br/> &lt;td&gt;{$smarty.section.row.index_prev}&lt;/td&gt;&lt;td&gt;{$rows[row.index_prev]}&lt;/td&gt;<br/> &lt;td&gt;{$smarty.section.row.index_next}&lt;/td&gt;&lt;td&gt;{$rows[row.index_next]}&lt;/td&gt;<br/> &lt;/tr&gt;<br/> {/section}<br/> &lt;/table&gt;</p> <p>The above example will output a table containing the following:<br/> index id index_prev prev_id index_next next_id<br/> 0 1001 -1 1 1002<br/> 1 1002 0 1001 2 1003<br/> 2 1003 1 1002 3 1004<br/> 3 1004 2 1003 4 1005<br/> 4 1005 3 1004 5</p></td> </tr></table> .iteration iteration contains the current loop iteration and starts at one. iteration包含當前的迭代循環,開始值為1。 <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/>This is not affected by the {section} properties start, step and max, unlike the index property. iteration also starts with one instead of zero unlike index. rownum is an alias to iteration, they are identical.<br/><p>.iteration不像.index屬性受start、step和max屬性的影響,該值總是從1開始(index是從0開始的)。.rownum是.iteration的別名,兩者意思一樣。</p><p>?</p></td> </tr></table> 譯注 | 本屬性用來統計循環迭代多少次。 | |-----| **Example 7.69. A section's iteration property 例 7-69. {section}的iteration屬性演示** <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><p>&lt;?php<br/> // array of 3000 to 3015<br/> $id = range(3000,3015);<br/> $smarty-&gt;assign('arr',$id);<br/> ?&gt;<br/> Template to output every other element of the $arr array as step=2<br/> {section name=cu loop=$arr start=5 step=2}<br/> iteration={$smarty.section.cu.iteration}<br/> index={$smarty.section.cu.index}<br/> id={$custid[cu]}&lt;br /&gt;<br/> {/section}<br/> The above example will output:<br/> iteration=1 index=5 id=3005&lt;br /&gt;<br/> iteration=2 index=7 id=3007&lt;br /&gt;<br/> iteration=3 index=9 id=3009&lt;br /&gt;<br/> iteration=4 index=11 id=3011&lt;br /&gt;<br/> iteration=5 index=13 id=3013&lt;br /&gt;<br/> iteration=6 index=15 id=3015&lt;br /&gt;</p> <p> Another example that uses the iteration property to output a table header block every five rows.<br/><br/>&lt;table&gt;<br/> {section name=co loop=$contacts}<br/> {if $smarty.section.co.iteration is div by 5}<br/>&lt;tr&gt;&lt;th&gt;&amp;nbsp;&lt;/th&gt;&lt;th&gt;Name&gt;&lt;/th&gt;&lt;th&gt;Home&lt;/th&gt;&lt;th&gt;Cell&lt;/th&gt;&lt;th&gt;Email&lt;/th&gt;&lt;/tr&gt;<br/> {/if}<br/>&lt;tr&gt;<br/>&lt;td&gt;&lt;a href="view.php?id={$contacts[co].id}"&gt;view&lt;a&gt;&lt;/td&gt;<br/>&lt;td&gt;{$contacts[co].name}&lt;/td&gt;<br/>&lt;td&gt;{$contacts[co].home}&lt;/td&gt;<br/>&lt;td&gt;{$contacts[co].cell}&lt;/td&gt;<br/>&lt;td&gt;{$contacts[co].email}&lt;/td&gt;<br/>&lt;tr&gt;<br/> {/section}<br/>&lt;/table&gt;<br/> An that uses the iteration property to alternate a text color every third row.<br/><br/>&lt;table&gt;<br/> {section name=co loop=$contacts}<br/> {if $smarty.section.co.iteration is even by 3}<br/>&lt;span style="color: #ffffff"&gt;{$contacts[co].name}&lt;/span&gt;<br/> {else}<br/>&lt;span style="color: #dddddd"&gt;{$contacts[co].name}&lt;/span&gt;<br/> {/if}<br/> {/section}<br/>&lt;/table&gt;<br/></p> </td> </tr></table> <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td>Note<br/>The "is div by" syntax is a simpler alternative to the PHP mod operator syntax. The mod operator is allowed: {if $smarty.section.co.iteration % 5 == 1} will work just the same.<br/>is div by'語法是一個php模式語法的簡單替代,在.iteration模式中允許:{if $smarty.section.co.iteration % 5 == 1} ,在效果上與前者是一樣的。<p/></td> </tr></table> <table width="80%" border="0" cellpadding="2" cellspacing="2" class="note"><caption> 提示 </caption> <tr><td><br/>Note<br/>You can also use "is odd by" to reverse the alternating. <br/>你也可以用'is odd by'倒序交替。</td> </tr></table> ? .first first is set to TRUE if the current {section} iteration is the initial one. 如果當前循環第一次執行,first被設置為true。 .last last is set to TRUE if the current section iteration is the final one. 如果當前section迭代執行到最尾,last 被設置為true。 **Example 7.70. {section} property first and last 例 7-70. {section}的first和last屬性演示** <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> This example loops the $customers array, outputs a header block on the first iteration and on the last<br/> outputs the footer block. Also uses the total property.<br/> {section name=customer loop=$customers}<br/>{if $smarty.section.customer.first}<br/>&lt;table&gt;<br/>&lt;tr&gt;&lt;th&gt;id&lt;/th&gt;&lt;th&gt;customer&lt;/th&gt;&lt;/tr&gt;<br/>{/if}<br/>&lt;tr&gt;<br/>&lt;td&gt;{$customers[customer].id}}&lt;/td&gt;<br/>&lt;td&gt;{$customers[customer].name}&lt;/td&gt;<br/>&lt;/tr&gt;<br/>{if $smarty.section.customer.last}<br/>&lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;{$smarty.section.customer.total} customers&lt;/td&gt;&lt;/tr&gt;<br/>&lt;/table&gt;<br/>{/if}<br/>{/section}</td> </tr></table> ? .rownum rownum contains the current loop iteration, starting with one. It is an alias to iteration, they work identically. rownum包含當前循環迭代。從1開始。該屬性是iteration的別名,兩者是一樣的。 ? .loop loop contains the last index number that this {section} looped. This can be used inside or after the {section}. loop包含{section}上次循環時的最后索引值, 該值可以用于循環內部或循環結束后。 **Example 7.71. {section} property loop 例 7-71. {section}loop屬性演示** <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td><p> {section name=customer loop=$custid}<br/> {$smarty.section.customer.index} id: {$custid[customer]}&lt;br /&gt;<br/> {/section}<br/> There are {$smarty.section.customer.loop} customers shown above.<br/><br/> The above example will output:<br/> 0 id: 1000&lt;br /&gt;<br/> 1 id: 1001&lt;br /&gt;<br/> 2 id: 1002&lt;br /&gt;<br/> There are 3 customers shown above.</p> <p/></td> </tr></table> .show show is used as a parameter to section and is a boolean value. If FALSE, the section will not be displayed. If there is a {sectionelse} present, that will be alternately displayed. *show*是section的參數,為布爾值,如果設置為 false,該循環將不顯示。如果存在{sectionelse}子句,該字句將交替顯示。 **Example 7.72. show property 例 7-72. {section}show屬性演示** <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> Boolean $show_customer_info has been passed from the PHP application, to regulate whether or not this section shows.<br/> {section name=customer loop=$customers show=$show_customer_info}<br/>{$smarty.section.customer.rownum} id: {$customers[customer]}&lt;br /&gt;<br/>{/section}<br/>{if $smarty.section.customer.show}<br/>the section was shown.<br/>{else}<br/>the section was not shown.<br/>{/if}<br/><br/>The above example will output:<br/>1 id: 1000&lt;br /&gt;<br/>2 id: 1001&lt;br /&gt;<br/>3 id: 1002&lt;br /&gt;<br/>the section was shown.</td> </tr></table> .total total contains the number of iterations that this {section} will loop. This can be used inside or after a {section}. total包含{section}循環執行總的次數,可以在{section}執行中/后調用此屬性。 **Example 7.73. total property example 例 7-73. total屬性演示** <table border="0" bgcolor="#E0E0E0" width="100%"><tr><td> {section name=customer loop=$custid step=2}<br/>{$smarty.section.customer.index} id: {$custid[customer]}&lt;br /&gt;<br/>{/section}<br/>There are {$smarty.section.customer.total} customers shown above.<br/></td> </tr></table> 參見[{foreach}](#)、[{for}](#)和[$smarty.section](#)。 <table summary="Footer navigation table" width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="language.function.php.html" accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html" accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="language.function.while.html" accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">{php}</td><td width="34%" align="center" valign="top"><a href="language.builtin.functions.html" accesskey="U">Up</a></td><td width="33%" align="right" valign="top">{while}<br/> 循環</td></tr></table>
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看