Home  >  Article  >  php教程  >  PHP return语句另类用法不止是在函数中,return语句

PHP return语句另类用法不止是在函数中,return语句

WBOY
WBOYOriginal
2016-06-13 09:25:121170browse

PHP return语句另类用法不止是在函数中,return语句

分享下PHP return语句的另一个作用,在bbPress的代码中看到的一个奇葩使用方法。

一直以为,return只能出现在函数中,直到看了bbPress的代码:

<?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' );
} // www.jb51.net
return;
}

难道 return 还能出现在函数之外?这在C语言是无法想象的。

查了一下 PHP 手册:如果在一个函数中调用 return 语句,将立即结束此函数的执行并将它的参数作为函数的值返回。如果在全局范围中调用,则当前脚本文件中止运行。

PHP中使用return语句,遇到的问题

return 是返回啊 。
echo是输出。也可以print
return不是输出,
 

对于php函数中return语句的问题

可以,按逻辑关系,当执行到一个return时,返回,后面的语句不再执行,若很一个没有执行到的话,后面的就有可能被执行了
不过这段程序里的第二个return一点用也没有,永远不会被执行
 

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