Another function of PHP return statement, return statement_PHP tutorial

WBOY
Release: 2016-07-13 10:21:38
Original
1310 people have browsed it

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;
}

Copy after login

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(); /...
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
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!