2016-06-10 84 views
0

我有一个php文件config.php,它包含以下代码。如何阅读包含数组的PHP文件

$_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 
     ) 
    ) 
) 
); 

我想将这个文件读入一个变量,然后像数组一样读取变量。谁能帮忙?

+8

'包括(your_file)的;'不是使用$ _config变量 – splash58

+0

非常感谢@ splash58 – Atish

回答

1

只需用PHP它的意思的工作方式:

include('config.php'); 
echo $_config['db']['mysolidworks']['host']; 
0

您可以使用以下任何

<?php 
     $file_loc = 'SomeDir/config.php'; 
     require $file_loc; //Throw a fatal if it's not found 
     require_once $file_loc; //If this might be called somewhere else in your script, only include it once 
     include $file_loc; //Include but just show a warning if not found 
     include_once $file_loc; //Include if not already included and throw warning if not 
    ?>