首页 > 后端开发 > php教程 > 关键字break代码优化片断

关键字break代码优化片断

WBOY
发布: 2016-06-13 12:27:55
原创
920 人浏览过

关键字break代码优化片段

 

 

       <span style="color: #800080;">$data</span>=<span style="color: #0000ff;">array</span><span style="color: #000000;">();</span>       <span style="color: #008000;">//</span><span style="color: #008000;">循环页面</span>       <span style="color: #0000ff;">foreach</span>(<span style="color: #800080;">$config_content</span>['pages'] <span style="color: #0000ff;">as</span> <span style="color: #800080;">$page_type_key</span>=><span style="color: #800080;">$page_type_val</span><span style="color: #000000;">){</span>           <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$page_type_val</span>['page_type']==<span style="color: #800080;">$page_type</span><span style="color: #000000;">){</span>               <span style="color: #008000;">//</span><span style="color: #008000;">循环模块</span>               <span style="color: #0000ff;">foreach</span>(<span style="color: #800080;">$config_content</span>['pages'][<span style="color: #800080;">$page_type_key</span>]['blocks'] <span style="color: #0000ff;">as</span> <span style="color: #800080;">$block_type_key</span>=><span style="color: #800080;">$block_type_val</span><span style="color: #000000;">){</span>                   <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$block_type_val</span>['blocktype']==<span style="color: #800080;">$blocktype</span><span style="color: #000000;">){</span>                       <br>              <span style="color: #0000ff;">foreach</span>(<span style="color: #800080;">$_POST</span> <span style="color: #0000ff;">as</span> <span style="color: #800080;">$key</span>=><span style="color: #800080;">$val</span><span style="color: #000000;">){</span>                           <span style="color: #0000ff;">if</span>(<span style="color: #008080;">is_string</span>(<span style="color: #800080;">$val</span><span style="color: #000000;">)){</span>                               <span style="color: #800080;">$data</span>[<span style="color: #800080;">$key</span>] = <span style="color: #008080;">trim</span>(<span style="color: #800080;">$val</span><span style="color: #000000;">);</span>                           }<span style="color: #0000ff;">else</span><span style="color: #000000;">{</span>                               <span style="color: #800080;">$data</span>[<span style="color: #800080;">$key</span>] = <span style="color: #800080;">$val</span><span style="color: #000000;">;</span><span style="color: #000000;">                           }</span><span style="color: #000000;">                       }</span>                       <span style="color: #800080;">$config_content</span>['pages'][<span style="color: #800080;">$page_type_key</span>]['blocks'][<span style="color: #800080;">$block_type_key</span>]['settings']=<span style="color: #800080;">$data</span><span style="color: #000000;">;<br>              <span style="color: #0000ff;">break<span style="color: #000000;">;</span></span>//代码优化的地方,跳出内层的foreach循环</span><span style="color: #000000;">                   }               }</span>               <span style="color: #0000ff;">break</span><span style="color: #000000;">;//代码优化的地方<span style="color: #000000;">,跳出外层的foreach循环</span></span><span style="color: #000000;">           }       }</span>
登录后复制

 

 
 
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板