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