0
當前的陣列結構:爲父子關係PHP更改陣列訂單
Array
(
[0] => Array
(
[TASK_ID] => 2
[PARENT_TASKID] => 0
[TASK_LEVEL] => 0
)
[1] => Array
(
[TASK_ID] => 1
[PARENT_TASKID] => 0
[TASK_LEVEL] => 0
)
[2] => Array
(
[TASK_ID] => 4
[PARENT_TASKID] => 1
[TASK_LEVEL] => 1
)
[3] => Array
(
[TASK_ID] => 5
[PARENT_TASKID] => 1
[TASK_LEVEL] => 1
)
[4] => Array
(
[TASK_ID] => 6
[PARENT_TASKID] => 5
[TASK_LEVEL] => 2
)
[5] => Array
(
[TASK_ID] => 9
[PARENT_TASKID] => 2
[TASK_LEVEL] => 1
)
[6] => Array
(
[TASK_ID] => 10
[PARENT_TASKID] => 2
[TASK_LEVEL] => 1
)
)
你可以觀察到PARENT_TASKID
是TASK_ID
爲孩子的。例如:
Array
(
[TASK_ID] => 9
[PARENT_TASKID] => 2
)
這裏TASK_ID = 9
是TASK_ID = 2
孩子。請注意0。
Array (
[TASK_ID] => 2
[PARENT_TASKID] => 0
[TASK_LEVEL] => 0
)
我怎樣才能改變上述陣列格式,所以孩子陣列自帶其父之下,看起來象下面這樣:
[0] => Array
(
[TASK_ID] => 2
[PARENT_TASKID] => 0
[TASK_LEVEL] => 0
)
[1] => Array
(
[TASK_ID] => 9
[PARENT_TASKID] => 2
[TASK_LEVEL] => 1
)
[2] => Array
(
[TASK_ID] => 10
[PARENT_TASKID] => 2
[TASK_LEVEL] => 1
)
我不該做什麼以精確地放置在孩子父母的下方,但改變數組順序相應。