更新时间:2023-02-09 22:26:08
这个问题已经被回答了无数次了……在发布新问题之前,请先使用搜索.
This question has been answered countless of times... please use search before posting a new question.
无论如何,这是一种解决方案:
Anyway, here's one solution:
$strings = array(
'item1:item2:itemx',
'item1:item2:itemy',
'itemz'
);
$nested_array = array();
foreach($strings as $item) {
$temp = &$nested_array;
foreach(explode(':', $item) as $key) {
$temp = &$temp[$key];
}
$temp = array();
}
var_dump($nested_array);