我有一個數據集或數組,看起來像安排分層數據的級別
[
"foo",
"bar",
[
"gum",
"ball",
[
"fat",
"rubber",
],
"zoo",
"topia",
],
"ant",
"elephant",
"grass",
[
"hopper",
],
]
,我想通過自己的水平或深度將它們分組的功能。喜歡的東西:
[
"level 1" => ['foo','bar','ant','elephant','grass'],
"level 2" => ['gum','ball','zoo','topia','hopper'],
"level 3" => ['fat','rubber'],
]
編輯我澄清了源數據,因爲它似乎導致一些混亂
htt p://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ – Barmar