<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[smarty的foreach循环。。。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Fri, 09 May 2008 08:38:26 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	简单一维数组用smary输出：<br/><br/><textarea name="code" class="php" rows="15" cols="100">
&lt;?php
$arr = array(1000, 1001, 1002);
$smarty-&gt;assign(&#039;myArray&#039;, $arr);
?&gt;
</textarea><br/>Template to output $myArray in an un-ordered list<br/>用模板以无序列表输出$myArray<br/><textarea name="code" class="php" rows="15" cols="100">
&lt;ul&gt;
&#123;foreach from=$myArray item=foo&#125;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;&#123;$foo&#125;&lt;/li&gt;
&#123;/foreach&#125;
&lt;/ul&gt;
</textarea><br/>上例将输出：<br/><textarea name="code" class="php" rows="15" cols="100">
&lt;ul&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;1000&lt;/li&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;1001&lt;/li&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&lt;li&gt;1002&lt;/li&gt;
&lt;/ul&gt;
</textarea><br/>==============================================<br/><br/>PHP：<br/><textarea name="code" class="html" rows="15" cols="100">foreach ($_REQUEST[&#039;_idx_&#039;] as $key =&gt; $value)
&#123;
&nbsp;&nbsp;echo &#039;&lt;br&gt;&#039;.$key.&#039; --- &#039;.$value.&#039;&lt;br /&gt;&#039;;//每行一个循环
&#125;</textarea><br/><br/><br/>smarty:<br/>模板：<br/><br/><textarea name="code" class="html" rows="15" cols="100">&lt;html&gt;
&lt;head&gt;&lt;title&gt;这是一个foreach使用的例子&lt;/title&gt;&lt;/head&gt;
&lt;body&gt;
这里将输出一个数组：&lt;br&gt;
&lt;&#123;foreach from=$newsArray.array item=newsID&#125;&gt;
新闻编号：&lt;&#123;$newsID.newsID&#125;&gt;&lt;br&gt;
新闻内容：&lt;&#123;$newsID.newsTitle&#125;&gt;&lt;br&gt;&lt;hr&gt;
&lt;&#123;foreachelse&#125;&gt;
对不起，数据库中没有新闻输出！
&lt;&#123;/foreach&#125;&gt;
&lt;/body&gt;
&lt;/html&gt;</textarea><br/><br/><br/>PHP：<br/><br/><br/><textarea name="code" class="html" rows="15" cols="100">&lt;?php
/*********************************************
*
* 文件名： example6.php
* 作 用： 显示实例程序2
*
* 作 者： 大师兄
* Email： teacherli@163.com

* 修 正： forest
*********************************************/
include_once(&quot;../drivers/smarty/Smarty.class.php&quot;); 

$smarty = new Smarty(); 
/**/
$smarty-&gt;template_dir = &quot;./templates&quot;; 
$smarty-&gt;templates_c = &quot;./templates_c&quot;; 
$smarty-&gt;cache=&quot;./cache&quot;;

$smarty-&gt;cache_lifetime = 0;
$smarty-&gt;caching = true;
$smarty-&gt;left_delimiter = &quot;&lt;&#123;&quot;; 
$smarty-&gt;right_delimiter = &quot;&#125;&gt;&quot;;

$array[] = array(&quot;newsID&quot;=&gt;1, &quot;newsTitle&quot;=&gt;&quot;第1条新闻&quot;); 
$array[] = array(&quot;newsID&quot;=&gt;2, &quot;newsTitle&quot;=&gt;&quot;第2条新闻&quot;); 
$array[] = array(&quot;newsID&quot;=&gt;3, &quot;newsTitle&quot;=&gt;&quot;第3条新闻&quot;); 
$array[] = array(&quot;newsID&quot;=&gt;4, &quot;newsTitle&quot;=&gt;&quot;第4条新闻&quot;); 
$array[] = array(&quot;newsID&quot;=&gt;5, &quot;newsTitle&quot;=&gt;&quot;第5条新闻&quot;); 
$array[] = array(&quot;newsID&quot;=&gt;6, &quot;newsTitle&quot;=&gt;&quot;第6条新闻&quot;); 
$array_test=array(&quot;test&quot;=&gt;&quot;test&quot;,&quot;array&quot;=&gt;$array);
print_r($array_test);
$smarty-&gt;assign(&quot;newsArray&quot;, $array_test);

//编译并显示位于./templates下的index.tpl模板
$smarty-&gt;display(&quot;example6.tpl&quot;); 
?&gt; </textarea><br/><br/>便于记忆：<br/>假如php中有：<br/><br/><textarea name="code" class="html" rows="15" cols="100">$array[] = array(&quot;newsID&quot;=&gt;1, &quot;newsTitle&quot;=&gt;&quot;第1条新闻&quot;);
$array[] = array(&quot;newsID&quot;=&gt;2, &quot;newsTitle&quot;=&gt;&quot;第2条新闻&quot;);
$array[] = array(&quot;newsID&quot;=&gt;3, &quot;newsTitle&quot;=&gt;&quot;第3条新闻&quot;);
$array[] = array(&quot;newsID&quot;=&gt;4, &quot;newsTitle&quot;=&gt;&quot;第4条新闻&quot;);
$array[] = array(&quot;newsID&quot;=&gt;5, &quot;newsTitle&quot;=&gt;&quot;第5条新闻&quot;);
$array[] = array(&quot;newsID&quot;=&gt;6, &quot;newsTitle&quot;=&gt;&quot;第6条新闻&quot;);</textarea><br/>$tpl -&gt; assign(&quot;array&quot;,$array);//array在模板里面变为from $array<br/><br/>在模板里面：<br/><textarea name="code" class="html" rows="15" cols="100">&lt;&#123;foreach from=$array item=foreach&#125;&gt;
&lt;&#123;$foreach.newsID&#125;&gt;
&lt;&#123;$foreach.newsTitle&#125;&gt;
&lt;&#123;/foreach&#125;&gt;</textarea><br/>注意：foreach在foreach里没有$,在取值的时候就有了，array在模板里面变为有$&nbsp;&nbsp;<br/><br/><br/>
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] smarty的foreach循环。。。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>