Home  >  Article  >  Backend Development  >  Another function of PHP return statement, return statement_PHP tutorial

Another function of PHP return statement, return statement_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:21:381387browse

Another function of PHP return statement, return statement

I always thought that return can only appear in functions, until I looked at the bbPress code:

<&#63;php
require_once('./bb-load.php');

bb_repermalink(); // The magic happens here.

if ( $self ) {
 if ( strpos($self, '.php') !== false ) {
  require($self);
 } else {
  require( BB_PATH . 'profile-base.php' );
 }
 return;
}

Can return still appear outside a function? This is unimaginable in C language.

Check the PHP manual: If you call the return statement in a function, it will immediately end the execution of this function and return its parameters as the value of the function. If called in the global scope, the current script file aborts running.

Alas, I am too deeply poisoned by the C language.

What is the usage and actual function of return in PHP?

The usage of

return is actually not difficult, it means return;

If return is executed, the content after the return statement will not be executed;
return can be a function return value , or you can return a null value, it depends on your specific usage, for example:

function test($a){
if($a>10){
return "a> 10";
}else{
return "a<10";
}
$b=45;
$c=$b-$a;
echo $c;
}

In this example, when you call this function and give any number, it will return a string, and the code: $b=45;
$c =$b-$a;
echo $c;
will never be executed

Problems encountered when using the return statement in PHP

return means return.
echo is output. You can also print
return is not output,

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/854360.htmlTechArticleAnother function of the PHP return statement, the return statement always thought that return can only appear in functions, until I saw it bbPress code: phprequire_once('./bb-load.php');bb_repermalink(); /...
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