色偷偷偷久久伊人大杳蕉,色爽交视频免费观看,欧美扒开腿做爽爽爽a片,欧美孕交alscan巨交xxx,日日碰狠狠躁久久躁蜜桃

x
x

php 中 return exit break contiue 詳解

發(fā)布時(shí)間:2013-9-25 15:52    發(fā)布者:reggae
關(guān)鍵詞: php
return、break和contiue是語言結(jié)構(gòu),就如同if語句之類的,但是exit卻是個(gè)函數(shù)。

1.exit函數(shù)
作用:Output a message and terminate the current script
輸出一則消息并且終止當(dāng)前腳本。
如果一段文本中包括多個(gè)以 結(jié)束的腳本,exit退出所有腳本。
比如一篇php文本包括一下代碼,則不輸出為world。
  1. echo "hello";
  2. exit;
  3. ?>
  4. echo "world";
  5. ?>
復(fù)制代碼

語法格式:void表示沒有返回值。
void exit ([ string $status ] )
void exit ( int $status )
If status is a string, this function prints the status just before exiting.
如果status是一段字符串,這個(gè)函數(shù)在腳本退出前打印status。
If status is an integer, that value will also be used as the exit status. Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully.
如果status是一個(gè)整數(shù),這個(gè)整數(shù)會(huì)被作為退出狀態(tài)。退出狀態(tài)應(yīng)該從0到254,退出狀態(tài)255被PHP保留并禁止使用。狀態(tài)0被用來表示成功的終止程序。

2.return語言結(jié)構(gòu)的用法

作用:終止函數(shù)的執(zhí)行和從函數(shù)中返回一個(gè)值

3.break和continue

用在for,foreach,while,do..while 或者 switch 結(jié)構(gòu)中。

break 結(jié)束當(dāng)前 for,foreach,while,do..while 或者 switch 結(jié)構(gòu)的執(zhí)行。

break 可以接受一個(gè)可選的數(shù)字參數(shù)來決定跳出幾重循環(huán)。

代碼:

  1. $arr = array ('one', 'two', 'three', 'four', 'stop', 'five');
  2. while (list (, $val) = each ($arr)) {
  3. if ($val == 'stop') {
  4. break;
  5. }
  6. echo "$val
    \n";
  7. }


  8. $i = 0;
  9. while (++$i) {
  10. switch ($i) {
  11. case 5:
  12. echo "At 5
    \n";
  13. break 1;
  14. case 10:
  15. echo "At 10; quitting
    \n";
  16. break 2;
  17. default:
  18. break;
  19. }
  20. }
  21. ?>
復(fù)制代碼

continue 在循環(huán)結(jié)構(gòu)用用來跳過本次循環(huán)中剩余的代碼并開始執(zhí)行本循環(huán)結(jié)構(gòu)的下一次循環(huán)。

注: 注意在 PHP 中 switch 語句被認(rèn)為是作為 continue 目的的循環(huán)結(jié)構(gòu)。

continue 接受一個(gè)可選的數(shù)字參數(shù)來決定跳過幾重循環(huán)到循環(huán)結(jié)尾。

代碼:

  1. while (list ($key, $value) = each ($arr)) {
  2. if (!($key % 2)) { // skip odd members
  3. continue;
  4. }
  5. do_something_odd ($value);
  6. }

  7. $i = 0;
  8. while ($i++ < 5) {
  9. echo "Outer
    \n";
  10. while (1) {
  11. echo " Middle
    \n";
  12. while (1) {
  13. echo " Inner
    \n";
  14. continue 3;
  15. }
  16. echo "This never gets output.
    \n";
  17. }
  18. echo "Neither does this.
    \n";
  19. }
  20. ?>
復(fù)制代碼
以上是本文關(guān)于php 中 return exit break contiue 的詳解,希望本文對(duì)廣大php開發(fā)者有所幫助,感謝閱讀本文。更多php技術(shù)問題歡迎加群探討:256271784,驗(yàn)證碼:eec,不寫驗(yàn)證不予通過喲~

本文地址:http://m.54549.cn/thread-121347-1-1.html     【打印本頁】

本站部分文章為轉(zhuǎn)載或網(wǎng)友發(fā)布,目的在于傳遞和分享信息,并不代表本網(wǎng)贊同其觀點(diǎn)和對(duì)其真實(shí)性負(fù)責(zé);文章版權(quán)歸原作者及原出處所有,如涉及作品內(nèi)容、版權(quán)和其它問題,我們將根據(jù)著作權(quán)人的要求,第一時(shí)間更正或刪除。
您需要登錄后才可以發(fā)表評(píng)論 登錄 | 立即注冊(cè)

關(guān)于我們  -  服務(wù)條款  -  使用指南  -  站點(diǎn)地圖  -  友情鏈接  -  聯(lián)系我們
電子工程網(wǎng) © 版權(quán)所有   京ICP備16069177號(hào) | 京公網(wǎng)安備11010502021702
快速回復(fù) 返回頂部 返回列表