Php 获取另一个数组中多维数组的值
嗨,我有这个结构:Php 获取另一个数组中多维数组的值,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,嗨,我有这个结构: $GLOBALS['config'] = array( 'mysql' => array( 'host' => 'localhost', 'username' => 'root', 'password' => 'root', 'dbname' => 'databas
$GLOBALS['config'] = array(
'mysql' => array(
'host' => 'localhost',
'username' => 'root',
'password' => 'root',
'dbname' => 'database'
),
'session' => array(
'session_name' => 'user'
),
'remember' => array(
'cookie_name' => 'hash',
'cookie_expiry' => 604800
),
'folder' => array(
'root' => 'backend',
'header' => 'head',
'views' => 'views'
),
'database' => array(
'names' => 'utf8mb4',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
'driver' => 'pdo'
),
'url' => array(
'base_url' => 'http://www.example.com/backend/',
'document_root' => $_SERVER['DOCUMENT_ROOT'] . "/backend"
),
'languages' => array(
'english' => 'en',
'german' => 'de',
'greek' => 'gr'
),
'headers' => array(
'404' => 'HTTP/1.0 404 Not Found',
'401' => 'HTTP/1.0 401 Unauthorized',
'500' => 'HTTP/1.0 500 Internal Server Error',
'403' => 'HTTP/1.0 403 Forbidden'
),
'title' => array(
'login' => 'Admin Dashboard',
'register' => 'Admin Dashboard | User Registration',
)
);
我希望url/base\u url中的内容如下
'base_url' => 'http://www.example.com/'.$GLOBALS['config']['folder']['root'].'/'
因此,如果我更改文件夹,我只需在唯一位置更改名称,但会出现如下语法错误:
Notice: Undefined index: config in C:\xampp-php56\htdocs\backend\core\init.php on line 31
我想做的可能吗?如果可能的话,怎么做?漏点
“基本url'=>”$GLOBALS['config']['folder']['root']./”
“base_url'=>”$GLOBALS['config']['folder']['root']./”仍在定义数组时,无法访问其他数组索引。您定义数组的语句尚未完成,在初始语句完成之前,无法访问该数组 首先需要尽可能多地设置数组,然后返回并添加引用其他数组索引的数组元素 因此,首先只需像现在一样创建大数组,而不使用基本url
$GLOBALS['config'] = array(
...
);
现在返回并添加url/base\u url,您现在可以访问config
的数组索引
$GLOBALS['config']['url']['base_url'] = 'http://www.example.com/'.$GLOBALS['config']['folder']['root'].'/';
示例:在定义数组时,无法访问其他数组索引。您定义数组的语句尚未完成,在初始语句完成之前,无法访问该数组 首先需要尽可能多地设置数组,然后返回并添加引用其他数组索引的数组元素 因此,首先只需像现在一样创建大数组,而不使用基本url
$GLOBALS['config'] = array(
...
);
现在返回并添加url/base\u url,您现在可以访问config
的数组索引
$GLOBALS['config']['url']['base_url'] = 'http://www.example.com/'.$GLOBALS['config']['folder']['root'].'/';
示例:现在它说的是未定义的索引配置…我猜它看不到文件夹名为config,现在它说的是未定义的索引配置…我猜它看不到文件夹名为config。你不能在自己的数组定义中引用数组的索引。知道如何在这个url数组中引用文件夹数组吗?只要在定义数组后设置它。@BRG请参见下面的我的答案。您不能在自己的数组定义中引用数组的索引。知道如何引用此url数组中的文件夹数组吗?请在定义数组后设置它。@BRG请参见我的答案below@BRG我想你不明白。在定义数组时,不能访问数组索引。你不能做你想做的事。我正在向您展示实现这一点的正确方法,即使这不是您想要的。@BRG请参阅我刚才提到的示例链接included@BRG我想你不明白。在定义数组时,不能访问数组索引。你不能做你想做的事。我正在向您展示实现此目标的正确方法,即使这不是您想要的。@BRG请参阅我刚才包含的示例链接