duanbogan5878 2016-06-10 18:05
浏览 95
已采纳

如何读取包含数组的PHP文件

I have a php file, config.php and it contains following code.

$_config = array(

    'db' => array(
        'mysolidworks' => array(
        'host'      => 'localhost',
        'username'  => 'netvibes',
        'password'  => 'frakcovsea',
        'dbname'    => 'sw_mysolidworks',
        'driver_options' => array(
            PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
        )
    )
  )
);

I want to read this file into a variable and then read the variable like an array. Could anyone help?

  • 写回答

2条回答 默认 最新

  • doudizhu2222 2016-06-10 18:15
    关注

    Simply using PHP the way it's meant to work:

    include('config.php');
    echo $_config['db']['mysolidworks']['host'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?