#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 visitPHP 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!