foreach多层嵌套的问题,求解~!
<br /><?php <br /> $a1=explode(',','20,21');<br /> $b1=explode(',','20,21');<br /> $c1=explode(',','20,21');<br /> $d1=explode(',','20,21');<br /> $e1=explode(',','20,21');<br /> foreach($a1 as $a ){<br /> <br /> foreach($b1 as $b){<br /><br /> foreach($c1 as $c){<br /> <br /> foreach($d1 as $d){ <br /><br /> foreach($e1 as $e){ <br /> <br /> }<br /> <br /> }<br /> <br /> }<br /><br /><br /> }<br /> <br /> }<br />?><br />
Copy after login
页面报错内容:
渲染失败,具体错误:loop nest level reach limited!请问,
出现这个错误,是PHP本身的限制,
还是什么?
如果我一定要嵌套这么多层,
有没有什么好的解决办法呢?
谢谢,给点建议哈~!
------解决方案--------------------你嵌套的目的是因为$a1是一个多维数数组,$b1是$a1的子数组,$c1是$b1的子数组。
楼主给的例子并不合适,你的例子相当于$a1,$b1,$c1彼此是相互独立的一维数组,因此
像你那样遍历当然出不来结果了。
按照你的例子要想出结果只能是
<br /> foreach($a1 as $a ){<br /> echo $a;<br /> }<br /> foreach($b1 as $b ){<br /> echo $b;<br /> }<br />
Copy after login
$a1和$b1彼此相互独立,根本不存在任何关系
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