首頁  >  文章  >  後端開發  >  关键字break代码优化片断

关键字break代码优化片断

WBOY
WBOY原創
2016-06-13 12:27:55909瀏覽

关键字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>

 

 
 
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn