title: Get all children of a nested tree recursively
body: <p>Thanks everyone <br />
  I have a JSON nested tree that I want to retrieve only ids.<br />
  This is the result of my query.<br />
  My goal is to call a recusrive function and give it the parent id and it will return all children Ids. <br />
  <strong>Ps: I'm working with laravel, Eloquent</strong></p>
  
  <pre><code>[{
  "id": "1",
  "name": "albert",
  "children": [{
      "id": "5",
      "name": "George",
      "children": [{
          "id": "7",
          "name": "Julia"
      }, {
          "id": "9",
          "name": "Harry",
          "children": []
      }]
  }, {
      "id": "2",
      "name": "Richard",
      "children": []
      }]
  }]
  </code></pre>
  
  <p>I tried to make a recursive function but it doesn't work.</p>
  
  <pre><code>function displayArrayRecursively($childrenUnit) {
  foreach ($childrenUnit as $unit) {
      $ids[] = $unit-&gt;id;
      if ($unit-&gt;childrenUnit) {
          displayArrayRecursively(Unit::find($unit-&gt;id)-&gt;childrenUnit);
      } else {
          return $ids;
      }
  }}
  </code></pre>
  
  <p>any help</p>