1 回答
TA贡献1780条经验 获得超5个赞
我不明白你想要什么names,但是这段代码正在生成你想要的数组:
$array = [
'A',
'B',
'C'
//and so on
];
$result = [];
for($i = count($array) - 1 ; $i >= 0 ; $i--){
$result = [
'value' => $array[$i],
'names' => [
'1' => $array[$i],
'2' => $array[$i],
],
'child' => $result
];
}
输出:
Array
(
[value] => A
[names] => Array
(
[1] => A
[2] => A
)
[child] => Array
(
[value] => B
[names] => Array
(
[1] => B
[2] => B
)
[child] => Array
(
[value] => C
[names] => Array
(
[1] => C
[2] => C
)
[child] => Array
(
)
)
)
)
- 1 回答
- 0 关注
- 79 浏览
添加回答
举报