我發現了一個代碼片段,它接收了一個數組並將其組織在父級子級多級組織中。像下面這樣將php數組組織成多層次的子級父組織
$phases = array(
array('id'=>1,'name'=>'First Step','parent_id'=>0,'percentage'=>.50,'order'=>1),
array('id'=>2,'name'=>'Second Step','parent_id'=>0, 'percentage'=>.50,'order'=>2),
array('id'=>3,'name'=>'Third Step','parent_id'=>2, 'percentage'=>.25,'order'=>3),
array('id'=>4,'name'=>'Fourth Step','parent_id'=>2, 'percentage'=>.25,'order'=>1),
array('id'=>5,'name'=>'Fifth Step','parent_id'=>2, 'percentage'=>.25,'order'=>1),
array('id'=>6,'name'=>'Sixth Step','parent_id'=>2, 'percentage'=>.25,'order'=>1),
);
它能夠將所有的子數組添加到他們尊敬的父項下。我找不到那個代碼。人有一個想法
比如,結果會是id = 2的數組會有一個'children'元素,它是一個包含元素id = 2-6的數組?你能舉一個例子嗎?謝謝。 – Wiseguy