如何存储从另一个文件返回的数组变量?

How to store array variable returned from another file?

我在 TYPO3 中有一个 PHP 配置文件,例如

<?php
return array(
    'DB' => array(
        'database' => 'vicous',
        'extTablesDefinitionScript' => 'extTables.php',
        'host' => 'localhost',
        'password' => '',
        'socket' => '',
        'username' => 'root',
    )
);
?>

我想在外部 php 文件中获取此数组。如何获得?

像这样。

function getArray("filepath"){
   $variable = filepath return that array
}

我的要求是在 $variable

中获取数组

includerequire 的行为完全符合您的要求:

$variable = include 'path/to/file.php';

来自the docs

It is possible to execute a return statement inside an included file in order to terminate processing in that file and return to the script which called it. Also, it's possible to return values from included files. You can take the value of the include call as you would for a normal function.

你可以使用 like

function getArray($path){
   return $variable = require_once( $path );
}