翻阅古今
我不明白你想要什么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 ( ) ) ))