return、break和contiue是語(yǔ)言結構,就如同if語(yǔ)句之類(lèi)的,但是exit卻是個(gè)函數。 1.exit函數 作用:Output a message and terminate the current script 輸出一則消息并且終止當前腳本。 如果一段文本中包括多個(gè)以 結束的腳本,exit退出所有腳本。 比如一篇php文本包括一下代碼,則不輸出為world。
語(yǔ)法格式:void表示沒(méi)有返回值。 void exit ([ string $status ] ) void exit ( int $status ) If status is a string, this function prints the status just before exiting. 如果status是一段字符串,這個(gè)函數在腳本退出前打印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è)整數,這個(gè)整數會(huì )被作為退出狀態(tài)。退出狀態(tài)應該從0到254,退出狀態(tài)255被PHP保留并禁止使用。狀態(tài)0被用來(lái)表示成功的終止程序。 2.return語(yǔ)言結構的用法 作用:終止函數的執行和從函數中返回一個(gè)值 3.break和continue 用在for,foreach,while,do..while 或者 switch 結構中。 break 結束當前 for,foreach,while,do..while 或者 switch 結構的執行。 break 可以接受一個(gè)可選的數字參數來(lái)決定跳出幾重循環(huán)。 代碼:
continue 在循環(huán)結構用用來(lái)跳過(guò)本次循環(huán)中剩余的代碼并開(kāi)始執行本循環(huán)結構的下一次循環(huán)。 注: 注意在 PHP 中 switch 語(yǔ)句被認為是作為 continue 目的的循環(huán)結構。 continue 接受一個(gè)可選的數字參數來(lái)決定跳過(guò)幾重循環(huán)到循環(huán)結尾。 代碼:
|