Home > Backend Development > PHP Tutorial > PHP文件直接返回一个数组是几个意思?

PHP文件直接返回一个数组是几个意思?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:40:55
Original
1391 people have browsed it

比如:

<code><?php return array(
    'app' => __DIR__.'/../app',
    'public' => __DIR__.'/../public',
    'base' => __DIR__.'/..'
);
</code>
Copy after login
Copy after login

数组没有变量名,在require这个文件的地方怎么使用这个数组里的数据呢?

回复内容:

比如:

<code><?php return array(
    'app' => __DIR__.'/../app',
    'public' => __DIR__.'/../public',
    'base' => __DIR__.'/..'
);
</code>
Copy after login
Copy after login

数组没有变量名,在require这个文件的地方怎么使用这个数组里的数据呢?

直接赋值

test.inc

<code><?php return array(
    'appname' => 'app',
    'version' => '1.0'
);
</code>
Copy after login

test.php

<code><?php $rtn_value = require('test.inc');
var_dump($rtn_value);
</code></code>
Copy after login

运行 test.php

<code>array(2) {
  ["appname"]=>
  string(3) "app"
  ["version"]=>
  string(3) "1.0"
}
</code>
Copy after login

中文PHP手册中的解释

如果在全局范围中调用,则当前脚本文件中止运行。如果当前脚本文件是被 include 的或者 require 的,则控制交回调用文件。此外,如果当前脚本是被 include 的,则 return 的值会被当作 include 调用的返回值。如果在主脚本文件中调用 return,则脚本中止运行。

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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template