0

So let's say I have this array:

array(

   array(
   'id' => 1,
   'level' => 1,
   'children' => array(
       array(
         'id' => 2,
         'level' => 2,
         'children' => array(
           'id' => 3,
           'level' => 3,
         )
       )
   ),
   array(
   'id' => 5,
   'level' => 1,
   'children' => array(
       array(
         'id' => 6,
         'level' => 2
       )
   )

)

So what I want to do is to get the last child of each hierarchy node with the MAX level, not just all the children with maximum level, but the maximum level of the current node, is better to do this in a MySQL query? or should I do it in PHP? and how?

D.Mendes
  • 159
  • 1
  • 11
Nervo Tan
  • 51
  • 6
  • Don't you hate it when people down-vote your question without providing any reasoning? That being said, you need to clarify your question. I don't understand what you mean by "max level." I also don't understand why you're nesting your array 3 deep, it only looks like you need 2. You should only be doing children=>array(id=>2....) not children=>array(array()) as that serves no purpose at all since you have nothing in the 2nd array. – Difster Nov 14 '18 at 10:56
  • Because MySQL is tagged possible duplicate of [How to create a MySQL hierarchical recursive query](https://stackoverflow.com/questions/20215744/how-to-create-a-mysql-hierarchical-recursive-query) – Raymond Nijland Nov 14 '18 at 11:02
  • What would be your desired output? level=>2 and level=>3 or just level=>3 ... not sure what are you meaning here by leaf...as this construct does not seems to be an binary tree... – Christian Felix Nov 14 '18 at 11:06

0 Answers0