23ghf02340rh20384f - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of 23ghf02340rh20384f.php

  1. <?php
  2. $tree = '{"name": "A","items" : [{"name": "B","items" : [{"name": "D"},{"name": "E","items" : [{"name": "G"}]}]},{"name": "C","items" : [{"name": "F","items" : [{"name": "H"},{"name": "I"}]}]}]}';
  3. $tree = json_decode($tree, 1);
  4.  
  5. treeTraversal($tree);
  6.  
  7. function treeTraversal(&$tree)
  8. {
  9.     if (!$tree['items']) {
  10.         return;
  11.     }
  12.  
  13.     $tree['count'] = count($tree['items']);
  14.     
  15.     foreach ($tree['items'] as &$item) {
  16.         treeTraversal($item);
  17.     }
  18. }
  19.  
  20. print_r($tree);
File Description
  • 23ghf02340rh20384f
  • PHP Code
  • 21 Oct-2021
  • 485 Bytes
You can Share it: