Home >Backend Development >PHP Problem >What are the keywords used by php for function return

What are the keywords used by php for function return

藏色散人
藏色散人Original
2019-10-10 10:13:356503browse

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;

Output:

2

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;

Output:

2

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!

Statement:
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
Previous article:Is php developing?Next article:Is php developing?