Home > Backend Development > PHP Tutorial > 关键字break代码优化片断

关键字break代码优化片断

WBOY
Release: 2016-06-13 12:27:55
Original
919 people have browsed it

关键字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>
Copy after login

 

 
 
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template