Home >Backend Development >PHP Tutorial >Keyword break code optimization snippet, _PHP tutorial
<span>$data</span>=<span>array</span><span>(); </span> <span>//</span><span>循环页面</span> <span>foreach</span>(<span>$config_content</span>['pages'] <span>as</span> <span>$page_type_key</span>=><span>$page_type_val</span><span>){ </span> <span>if</span>(<span>$page_type_val</span>['page_type']==<span>$page_type</span><span>){ </span> <span>//</span><span>循环模块</span> <span>foreach</span>(<span>$config_content</span>['pages'][<span>$page_type_key</span>]['blocks'] <span>as</span> <span>$block_type_key</span>=><span>$block_type_val</span><span>){ </span> <span>if</span>(<span>$block_type_val</span>['blocktype']==<span>$blocktype</span><span>){</span> <br /> <span>foreach</span>(<span>$_POST</span> <span>as</span> <span>$key</span>=><span>$val</span><span>){ </span> <span>if</span>(<span>is_string</span>(<span>$val</span><span>)){ </span> <span>$data</span>[<span>$key</span>] = <span>trim</span>(<span>$val</span><span>); </span> }<span>else</span><span>{ </span> <span>$data</span>[<span>$key</span>] = <span>$val</span><span>; </span><span> } </span><span> } </span> <span>$config_content</span>['pages'][<span>$page_type_key</span>]['blocks'][<span>$block_type_key</span>]['settings']=<span>$data</span><span>;<br /> <span>break<span>;</span></span>//代码优化的地方,跳出内层的foreach循环 </span><span> } } </span> <span>break</span><span>;//代码优化的地方<span>,跳出外层的foreach循环</span> </span><span> } }</span>