Maison > développement back-end > tutoriel php > 关键字break代码优化片断

关键字break代码优化片断

WBOY
Libérer: 2016-06-13 12:27:55
original
920 Les gens l'ont consulté

关键字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>
Copier après la connexion

 

 
 
Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal