Not only one return statement is allowed in a function in PHP. In a PHP function, only one return statement can be executed; but multiple return statements can be written; because if the function executes the return statement, the life of the function is over, and the code following the return statement will not be executed.
Not only one return statement is allowed in a function in PHP.
If the function executes the return statement, then the life of the function is over, and the code after the return statement will not be executed. So to be precise, a return statement can only be executed once in a function, but multiple return statements can be written.
For example:
def test_return(x): if x > 0: return x else: return 0
Recommended tutorial: "php tutorial"
The above is the detailed content of Is there only one return statement allowed in a function in PHP?. For more information, please follow other related articles on the PHP Chinese website!