Is there only one return statement allowed in a function in PHP?

烟雨青岚
Release: 2023-03-02 08:10:01
Original
7164 people have browsed it

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.

Is there only one return statement allowed in a function in PHP?

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!