PHP 注意:数组到字符串的转换在第 10 行


PHP Notice: Array to string conversion on line 10

我是一个新手,用PHP编写了一些代码,这给了我上面提到的通知。我的程序运行良好,但我想解决通知。我知道我可以关闭通知,但我不想那样做。请让我知道我该如何解决它。

我的代码 -

$GLOBALS['config'] = array(
    'mysql' =>  array(
        'host'  =>  '127.0.0.1',
        'username'  =>  'root',
        'password'  =>  '',
        'database'  =>  'app'
    )
);

            $config = $GLOBALS['config'];
            $path = explode('/', 'mysql/host');
            foreach($path as $bit){                
                if(isset($config[$bit])){
                    $config = $config[$bit];
                }
            }
            echo $config;

我的输出来自

echo $config;

是 127.0.0.1,符合预期。

但我在网上收到通知——

$config = $GLOBALS['config'];

请帮忙。

尝试在

$config = $GLOBALS['config'] 之前添加此行

$config = array();