📄 control-structures.break.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>break</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="control-structures.foreach.html">foreach</a></div> <div class="next" style="text-align: right; float: right;"><a href="control-structures.continue.html">continue</a></div> <div class="up"><a href="language.control-structures.html">Control Structures</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="control-structures.break" class="sect1"> <h2 class="title"><i>break</i></h2> <p class="simpara"> <i>break</i> ends execution of the current <i>for</i>, <i>foreach</i>, <i>while</i>, <i>do-while</i> or <i>switch</i> structure. </p> <p class="simpara"> <i>break</i> accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of. </p> <p class="para"> <div class="informalexample"> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br />$arr </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'one'</span><span style="color: #007700">, </span><span style="color: #DD0000">'two'</span><span style="color: #007700">, </span><span style="color: #DD0000">'three'</span><span style="color: #007700">, </span><span style="color: #DD0000">'four'</span><span style="color: #007700">, </span><span style="color: #DD0000">'stop'</span><span style="color: #007700">, </span><span style="color: #DD0000">'five'</span><span style="color: #007700">);<br />while (list(, </span><span style="color: #0000BB">$val</span><span style="color: #007700">) = </span><span style="color: #0000BB">each</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">)) {<br /> if (</span><span style="color: #0000BB">$val </span><span style="color: #007700">== </span><span style="color: #DD0000">'stop'</span><span style="color: #007700">) {<br /> break; </span><span style="color: #FF8000">/* You could also write 'break 1;' here. */<br /> </span><span style="color: #007700">}<br /> echo </span><span style="color: #DD0000">"$val<br />\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">/* Using the optional argument. */<br /><br /></span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />while (++</span><span style="color: #0000BB">$i</span><span style="color: #007700">) {<br /> switch (</span><span style="color: #0000BB">$i</span><span style="color: #007700">) {<br /> case </span><span style="color: #0000BB">5</span><span style="color: #007700">:<br /> echo </span><span style="color: #DD0000">"At 5<br />\n"</span><span style="color: #007700">;<br /> break </span><span style="color: #0000BB">1</span><span style="color: #007700">; </span><span style="color: #FF8000">/* Exit only the switch. */<br /> </span><span style="color: #007700">case </span><span style="color: #0000BB">10</span><span style="color: #007700">:<br /> echo </span><span style="color: #DD0000">"At 10; quitting<br />\n"</span><span style="color: #007700">;<br /> break </span><span style="color: #0000BB">2</span><span style="color: #007700">; </span><span style="color: #FF8000">/* Exit the switch and the while. */<br /> </span><span style="color: #007700">default:<br /> break;<br /> }<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="control-structures.foreach.html">foreach</a></div> <div class="next" style="text-align: right; float: right;"><a href="control-structures.continue.html">continue</a></div> <div class="up"><a href="language.control-structures.html">Control Structures</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -