<?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[[个人原创]Warning: Invalid argument supplied for foreach 最简单解决方法]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Php/Js/Shell/Go]]></category>
<pubDate>Mon, 26 Dec 2011 08:00:32 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	经常对提交过来的数据进行双重循环，或者如下的for循环，但是数组为空时会报错：<br/><textarea name="code" class="html" rows="15" cols="100">
for($i=0;$i&lt;$count;$i++)
&#123;
&nbsp;&nbsp;$tstSumOptionArr = $dbObj-&gt;getResult($Id,$Num);
&nbsp;&nbsp;foreach((array)$tstSumOptionArr as $key=&gt;$value)////数据结构整理：这行是强制当null时为数组，有点像C的强制类型转换
&nbsp;&nbsp;&#123;


&nbsp;&nbsp;&#125;
&#125;
</textarea><br/>这里的$tstSumOptionArr是由数据库查询出来的，有可能为Null,所以PHP在foreach 一个Null时会报警，而在前面强制一个这个是数组就不会报警了。<br/>否则，你可能会这样来处理，如下：<br/><textarea name="code" class="html" rows="15" cols="100">
for($i=0;$i&lt;$count;$i++)
&#123;
&nbsp;&nbsp;$tstSumOptionArr = $dbObj-&gt;getResult($Id,$Num);
&nbsp;&nbsp;if($tstSumOptionArr != null)
&nbsp;&nbsp;&#123;
&nbsp;&nbsp;&nbsp;&nbsp;foreach((array)$tstSumOptionArr as $key=&gt;$value)
&nbsp;&nbsp;&nbsp;&nbsp;&#123;


&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&#125;
&#125;
</textarea>
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [个人原创]Warning: Invalid argument supplied for 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>