I have a little problem. I have make a config class which automaticlly return the value that i want.
usage example:
echo Config::get('database.host');
This returns localhost.
But if i have multiple vars then it returns the first i selected.
example:
echo Config::get('database.host');
echo Config::get('database.username');
echo Config::get('database.password');
echo Config::get('database.name');
all returns localhost.
here is my config class:
<?php
namespace App\Libraries;
class Config
{
private static $_config;
public static function set($config)
{
self::$_config = $config;
}
public static function get($var = null)
{
$var = explode('.', $var);
foreach ($var as $key) {
if (isset(self::$_config[$key])) {
self::$_config = self::$_config[$key];
}
}
return self::$_config;
}
public function __destruct()
{
self::$_config = null;
}
}
?>
i initialisate it like this:
Config::set($config);
the $config variable contains my entire config file:
<?php
$config = [
'database' => [
'host' => 'localhost',
'name' => 'dev',
'charset' => 'utf8',
'username' => 'root',
'password' => '1234'
]
];
?>
Hope you can help me guys :) (Sorry for bad english)