return、break和contiue是語(yǔ)言結(jié)構(gòu),就如同if語(yǔ)句之類的,但是exit卻是個(gè)函數(shù)。 1.exit函數(shù) 作用:Output a message and terminate the current script 輸出一則消息并且終止當(dāng)前腳本。 如果一段文本中包括多個(gè)以 結(jié)束的腳本,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è)函數(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被用來(lái)表示成功的終止程序。 2.return語(yǔ)言結(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ù)來(lái)決定跳出幾重循環(huán)。 代碼:
continue 在循環(huán)結(jié)構(gòu)用用來(lái)跳過(guò)本次循環(huán)中剩余的代碼并開始執(zhí)行本循環(huán)結(jié)構(gòu)的下一次循環(huán)。 注: 注意在 PHP 中 switch 語(yǔ)句被認(rèn)為是作為 continue 目的的循環(huán)結(jié)構(gòu)。 continue 接受一個(gè)可選的數(shù)字參數(shù)來(lái)決定跳過(guò)幾重循環(huán)到循環(huán)結(jié)尾。 代碼:
|