How to create tree in php? -
i trying generate tree in php. here code it
$company = array(); $i = 1; foreach($final_array3 $key => $value) { array_push($company, $value); $i++; }
main array is
array ( [ordinary income/expense] => array ( [0] => stdclass object ( [compid] => 1 [coaid] => 12877 [item] => ordinary income/expense [category] => 0 [auto] => 0 [jan_2015_budget] => 0 [feb_2015_budget] => 0 [mar_2015_budget] => 0 [apr_2015_budget] => 0 [sum(if(`trl`.`entrydate` between '2016-1-01' , '2016-02-26', `trl`.`itemvalue`, 0))] => 0 [istotal] => 0 [isparent] => 1 ) [1] => stdclass object ( [compid] => 2 [coaid] => 13571 [item] => ordinary income/expense [category] => 0 [auto] => 0 [jan_2015_budget] => 0 [feb_2015_budget] => 0 [mar_2015_budget] => 0 [apr_2015_budget] => 0 [sum(if(`trl`.`entrydate` between '2016-1-01' , '2016-02-26', `trl`.`itemvalue`, 0))] => 0 [istotal] => 0 [isparent] => 0 ) ) [income] => array ( [0] => stdclass object ( [compid] => 1 [coaid] => 12878 [item] => income [category] => 12877 [auto] => 1 [jan_2015_budget] => 0 [feb_2015_budget] => 0 [mar_2015_budget] => 0 [apr_2015_budget] => 0 [sum(if(`trl`.`entrydate` between '2016-1-01' , '2016-02-26', `trl`.`itemvalue`, 0))] => 0 [istotal] => 0 [isparent] => 1 ) [1] => stdclass object ( [compid] => 2 [coaid] => 13572 [item] => income [category] => 13571 [auto] => 1 [jan_2015_budget] => 0 [feb_2015_budget] => 0 [mar_2015_budget] => 0 [apr_2015_budget] => 0 [sum(if(`trl`.`entrydate` between '2016-1-01' , '2016-02-26', `trl`.`itemvalue`, 0))] => 0 [istotal] => 0 [isparent] => 0 ) ) )
and desired output is
array ( [ordinary income/expense] => array ( [0] => stdclass object ( [compid] => 1 [coaid] => 12877 [item] => ordinary income/expense [category] => 0 [auto] => 0 [jan_2015_budget] => 0 [feb_2015_budget] => 0 [mar_2015_budget] => 0 [apr_2015_budget] => 0 [sum(if(`trl`.`entrydate` between '2016-1-01' , '2016-02-26', `trl`.`itemvalue`, 0))] => 0 [istotal] => 0 [isparent] => 1 [children] => stdclass object( [compid] => 1 [coaid] => 12878 [item] => income [category] => 12877 [auto] => 1 [jan_2015_budget] => 0 [feb_2015_budget] => 0 [mar_2015_budget] => 0 [apr_2015_budget] => 0 [sum(if(`trl`.`entrydate` between '2016-1-01' , '2016-02-26', `trl`.`itemvalue`, 0))] => 0 [istotal] => 0 [isparent] => 1 ) ) [1] => stdclass object ( [compid] => 2 [coaid] => 13571 [item] => ordinary income/expense [category] => 0 [auto] => 0 [jan_2015_budget] => 0 [feb_2015_budget] => 0 [mar_2015_budget] => 0 [apr_2015_budget] => 0 [sum(if(`trl`.`entrydate` between '2016-1-01' , '2016-02-26', `trl`.`itemvalue`, 0))] => 0 [istotal] => 0 [isparent] => 0 [children] => stdclass object( [compid] => 2 [coaid] => 13572 [item] => income [category] => 13571 [auto] => 1 [jan_2015_budget] => 0 [feb_2015_budget] => 0 [mar_2015_budget] => 0 [apr_2015_budget] => 0 [sum(if(`trl`.`entrydate` between '2016-1-01' , '2016-02-26', `trl`.`itemvalue`, 0))] => 0 [istotal] => 0 [isparent] => 0 ) ) ) )
so want make category tree. parent child relation coaid in stdclass object parent , category same coaid key in stdcalss object children.
now can please suggest me how this.tree can 5 level hierarchy.
thanks
Comments
Post a Comment