내 뇌가 천천히 시작하는 것 같아요,하지만이 테이블에서 내 결과의 재귀 배열을 얻으려면 함께 테이블에서 간단한 재귀를 가져옵니다 :id_parent
:|id|int(11)|
|name|varchar(150)|
|type|tinyint(4)|
|id_parent|mediumint(9)|
|1|Marque forte|1|0|
|2|Communication|2|1|
|3|Respect du CI|0|2|
|4|Stratégie digitale|0|2
|5|Expérience de marque|2|1|
|6|Gastronomie|0|5|
나는 배열처럼 원하는
array('id' => array('name' => $name, 'childs' => array(...), 'id' => ...)
데이터 배열을 하나의 배열로 주문하고 싶습니다.
는 지금까지이 시도 : 나에게 이상한 결과를 제공// returns array of objects - codeigniter result
$dbResult = $this->db->get_where('table')->result();
// will contains the array
$this->data['tree'] = array();
$this->getRecursive(0, 0, $dbResult);
....
private function getRecursive($parent, $niveau, $result)
{
foreach ($result AS $row)
{
if ($parent == $row->id_parent)
{
$this->data['tree'][] = array($row->name => $this->getRecursive($row->id, ($niveau + 1), $result));
}
}
}
이 ...
아주 좋은 감사를해야 다음! 나도 모르겠다. 내 뇌는 재귀적일 때 꺼져있다 .. –
당신은 환영합니다 :) –