title: Get tree by recursion
body: <p>I have a flat array with each element containing an 'InstitutionId' and a 'ParentInstitutionId'. Each element will only have ONE parent, but may have multiple children. I know it need recursive solution, I am stuck and can't find way out.</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [InstitutionId] =&gt; 17507
              [InstitutionName] =&gt; abc
              [ParentInstitutionId] =&gt; 60936
          )
  
      [1] =&gt; Array
          (
              [InstitutionId] =&gt; 41679
              [InstitutionName] =&gt; abc
              [ParentInstitutionId] =&gt; 55701
          )
  
      [2] =&gt; Array
          (
              [InstitutionId] =&gt; 55701
              [InstitutionName] =&gt; abc
              [ParentInstitutionId] =&gt; 
          )
  
      [3] =&gt; Array
          (
              [InstitutionId] =&gt; 60936
              [InstitutionName] =&gt; abc 
              [ParentInstitutionId] =&gt; 128629
          )
  
      [4] =&gt; Array
          (
              [InstitutionId] =&gt; 71737
              [InstitutionName] =&gt; abc
              [ParentInstitutionId] =&gt; 17507
          )
  
  )
  </code></pre>
  
  <p>How can I make this a tree, children and there children should come under one array starting from root.</p>