PHP中return的用法
来源:互联网 发布:linux中怎么安装gcc 编辑:程序博客网 时间:2024/06/05 03:52
今天研究了一下CI框架的使用,注意到他的配置文件,采用一种写法。如下:
return array(
'config1' => 'somevalue',
'config2' => 'somevalue',
);
?>
在这个文件中,直接就写了一个return,这个用法又一次突破了我的常识。特意查询了一下文档,里面这样描述的:
return
If calledfrom within a function, the return() statement immediately endsexecution of the current function, and returns its argument as thevalue of the function call. return() will also end the execution ofan eval_r() statement or script file.
If calledfrom the global scope, then execution of the current script file isended. If the current script file was include()ed or require()ed,then control is passed back to the calling file. Furthermore, ifthe current script file was include()ed, then the value given toreturn() will be returned as the value of the include() call. Ifreturn() is called from within the main script file, then scriptexecution ends. If the current script file was named by theauto_prepend_file or auto_append_file configuration options inphp.ini, then that script file's execution isended.
return语句可以终止函数执行那自不必说了,这里还提到了可以终止eval过程的进行,并且如果处于被include的文件中,还能使return的值成为include和require函数的返回值。这样写的好处是,一个语句就可以得到配置项的内容了。
//原来这样写
require './config.php';
function test() {
global$config;
if ($config['a']=='b') echo'hello';
}
//现在
function test() {
$config =require('./config.php');
if ($config['a']=='b') echo'hello';
}
?>
return array(
);
?>
在这个文件中,直接就写了一个return,这个用法又一次突破了我的常识。特意查询了一下文档,里面这样描述的:
return
return语句可以终止函数执行那自不必说了,这里还提到了可以终止eval过程的进行,并且如果处于被include的文件中,还能使return的值成为include和require函数的返回值。这样写的好处是,一个语句就可以得到配置项的内容了。
//原来这样写
require './config.php';
function test() {
}
//现在
function test() {
}
?>
0 0
- PHP中return的用法
- PHP中return的用法
- PHP中return的用法
- PHP中return用法
- PHP中return返回数组的一点用法
- php中return die exit用法梳理
- PHP中return用法详细解读
- php 中return、exit()、die()用法比较
- JAVA中 return的用法
- js中return的用法
- Java中return的用法
- js中return的用法
- JAVA中 return的用法
- js中return的用法
- Java中return的用法
- js中return的用法
- js中return的用法
- Java中return的用法
- 将图片转换成caffe的lmdb形式并进行实验
- 采用PHP函数memory_get_usage获取P…
- $_SERVER['SCRIPT_FILENAME']&nbsp…
- PHP OR 语句
- set_include_path和get_incl…
- PHP中return的用法
- PHP static静态变量
- PHP中的一些路径变量或函数
- Javassist简单应用小结
- preg_replace的/e修饰符妙用与慎用
- php的正则表达式 '/\b\w…
- ThinkPHP的标签制作及标签调用解析…
- 线程池的原理及实现
- iOS开发中方法延迟执行的几种方式-简书