我有一個這樣的字符串:鴻溝字符串assoc命令陣列
$config = 'app.name = "My App";
app.id = "myappid";
app.components.cache.id = "Memcache";';
我需要將其轉換成數組是這樣的:
app=>[
'name=>'My App',
'id'=>'myappid',
'components'=>[
'cache'=>['id'=>'Memcache']
]
]
我使用爆炸,對上個鴻溝,但我不知道接下來我需要做什麼。
$arr = explode(";", $config);
$data = [];
foreach ($arr as $item) {
$pieces = explode('=', $item);
$pieces_dotes = explode('.', $pieces[0]);
foreach ($pieces_dotes as $piece) {
//what i need to do here?
}
}