如何从 PHP 文件加载返回数组? [英] How to load return array from a PHP file?
本文介绍了如何从 PHP 文件加载返回数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 PHP 文件,一个来自 Yii 消息翻译文件的配置文件,其中包含:
I have a PHP file a configuration file coming from a Yii message translation file which contains this:
<?php
return array(
'key' => 'value'
'key2' => 'value'
);
?>
我想从另一个文件加载这个数组并将其存储在一个变量中
I want to load this array from another file and store it in a variable
我尝试这样做,但没有用
I tried to do this but it doesn't work
function fetchArray($in)
{
include("$in");
}
$in
是 PHP 文件的文件名
$in
is the filename of the PHP file
任何想法如何做到这一点?
Any thoughts how to do this?
推荐答案
当一个被包含的文件返回一些东西时,你可以简单地将它赋值给一个变量
When an included file returns something, you may simply assign it to a variable
$myArray = include $in;
参见 http://php.net/manual/function.include.php#example-126
这篇关于如何从 PHP 文件加载返回数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文