Php 按键名选择数组值

Php 按键名选择数组值,php,arrays,Php,Arrays,在我收到一阵嘲笑之前,请相信我——我已经用谷歌搜索过了 如何按名称选择数组值 如果我想调用特定的值(对于db连接),我在这里怎么做?以下是基于php的CMS站点配置文件夹中的database.php文件 我想为mysqli查询创建连接 $db_connection = @mysqli_connect(host,user,pass,database) 下面的代码存在于站点的config文件夹config/database.php中的单独文件中 $config['default'] = array

在我收到一阵嘲笑之前,请相信我——我已经用谷歌搜索过了

如何按名称选择数组值

如果我想调用特定的值(对于db连接),我在这里怎么做?以下是基于php的CMS站点配置文件夹中的database.php文件

我想为mysqli查询创建连接

$db_connection = @mysqli_connect(host,user,pass,database)
下面的代码存在于站点的config文件夹config/database.php中的单独文件中

$config['default'] = array(
        'benchmark' => TRUE,
        'persistent' => FALSE,
        'connection' => array(
            'type' => 'mysqli',
            'user' => 'myname',
            'pass' => 'somepass123',
            'host' => 'localhost',
            'port' => FALSE,
            'socket' => FALSE,
            'database' => 'local_sitename',
        ),
        'character_set' => 'utf8',
        'table_prefix' => '',
        'object' => TRUE,
        'cache' => FALSE,
        'escape' => TRUE
    );
互联网和我的课本上都有这样的例子:

其中,例如,是一个季节数组:

<?php

$seasons = array("Autumn", "Winter", "Spring", "Summer");
print $seasons[0];

?>

如何调用这些值?

使用字符串按键索引数组:

$config['default']['connection']['host'];// === 'localhost'

$config['default']['connection']['host']
-基本阵列访问。感谢您的回答。所以,这看起来很长,在PHP中有没有更短的方法?我尝试了$config['connection'],因为连接似乎是一个包含所有必需信息的数组。设置连接有多种方法。您可以将其存储在常量->或基本变量中,也可以仅为数据库创建配置数组感谢您花时间回答我,我意识到这对于那些学习php的人来说是基本的tag@Doug不是那些“跟随PHP标签”的人。那些阅读手册并通过阅读教程或书籍来学习PHP的人。我建议你多做这两件事。
$config['default']['connection']['host'];// === 'localhost'
$config['default'] = array(
        'benchmark' => TRUE,
        'persistent' => FALSE,
        'connection' => array(
            'type' => 'mysqli',
            'user' => 'myname',
            'pass' => 'somepass123',
            'host' => 'localhost',
            'port' => FALSE,
            'socket' => FALSE,
            'database' => 'local_sitename',
        ),
        'character_set' => 'utf8',
        'table_prefix' => '',
        'object' => TRUE,
        'cache' => FALSE,
        'escape' => TRUE
    );


echo $config['default']['connection']['user'] // prints myname
echo $config['default']['connection']['pass'] // prints pass
echo $config['default']['connection']['host'] // prints host