如何在php中将定界字符串转换为关联数组?

时间:2019-10-29 09:27:56

标签: php laravel-5.8

如何在PHP中转换以下内容?

[
    'common.header.home' => 'Home',
    'common.header.blog' => 'Blog',
    'common.header.features' => 'Features',
    'common.header.api' => 'SMS API',
]

TO

[
    'common' => [
        'header' => [
            'home' => 'Home',
            'blog' => 'Blog',
            'features' => 'Features',
            'api' => 'SMS API',
         ]
    ]
]

并将其另存为php文件。

我尝试使用以下逻辑:

protected function calc($param, $value)
{
    if (count($param))
    {
        $key = array_shift($param);
        $result[$key] = $this->calc($param, $value);
        return $result;
    }
    return $value;
}

这称为$this->calc($key, $value);

我如何实现解决方案?

0 个答案:

没有答案