What are the keywords used by php for function return

藏色散人
Release: 2023-02-26 06:18:01
Original
6375 people have browsed it

What are the keywords used by php for function return

#What are the keywords that php uses for function returns?

The keyword used by php for function return is return.

Using the return keyword allows the function to return a value, which can return any type including arrays and objects. If return is omitted, the default return value is NULL.

function add($a) {
    return $a+1;
}
$b = add(1);
echo $b;
Copy after login

Output:

2
Copy after login
Copy after login

The return statement immediately aborts the running of the function and returns control to the line of code that called the function. The function cannot return multiple values, but it can return one by array to achieve a similar effect. Therefore, the return value of the following function is the same as the above function.

function add($a) {
    return $a+1;
    $a = 10;
    return $a+20;
}
$b = add(1);
echo $b;
Copy after login

Output:

2
Copy after login
Copy after login

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of What are the keywords used by php for function return. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
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
Popular Tutorials
More>
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!