In my model, I have a series of objects, each of which is stored with their parent identifier. I use the Adjacency list model as a hierarchy method.
All examples of the Adjacency list are simply displayed there and then. None of them are trying to create a multidimensional array from a result set.
--------------- | id | parent | --------------- | 1 | NULL | | 2 | 1 | | 3 | 1 | | 4 | 2 | | 5 | 2 | | 6 | 5 | ---------------
I created an array variable in my class called "children" and I want to add a child object every time I find a child from a db request.
. ? , .
, ?
PHP, ?
; ad-hoc-, node , . PHP, :
{ object => $row1, children => [ { object => $row2, children => [ ... ], }, { object => $row3, children => [], } ] }
, ? , , :
http://www.php.net/~helly/php/ext/spl/classRecursiveArrayIterator.html
- .
SPL , , . .
Source: https://habr.com/ru/post/1715109/More articles:ZF routing task - phpVariables in the creation record - variables.net - designИспользование jQuery для захвата высоты изображения - jqueryPassing an object from F # to a C # method that takes it as an out parameter doesn't work? - pass-by-referenceCreating C ++ BackTraces on OS / X (10.5.7) - c ++Drupal: staying in organizations with module changes - phpFirefox jQuery error finding position () div - jqueryWPF Focus Navigation Wrapping - wpfDouble click prevention with server side validation - asp.netAll Articles