php_2 - 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 php_2.php

  1. <?php
  2. //$input['vs_portal'] = true;
  3. if (isset($input['vs_portal']) && ($input['vs_portal'] === true)) {
  4.     $input['vs_portal'] = true;
  5.     
  6. }
  7. // $bear = $input['vs_portal'] ?: false;
  8.  
  9.  
  10. $datas = array(
  11.  
  12.     array('id' => 1, 'parent_id' => 0, 'name' => (isset($input['vs_portal']))),
  13.     array('id' => 2, 'parent_id' => 1, 'name' => $bear),
  14.     );
  15.  
  16. function generatePageTree($datas, $parent = 0, $depth = 0) {
  17.     $ni=count($datas);
  18.     if($ni === 0 || $depth > 1000) return ''; // Make sure not to have an endless recursion
  19.     $tree = '<ul>';
  20.     for($i=0; $i < $ni; $i++){
  21.         if($datas[$i]['parent_id'] == $parent){
  22.             $tree .= '<li>';
  23.             $tree .= $datas[$i]['name'];
  24.             $tree .= generatePageTree($datas, $datas[$i]['id'], $depth+1);
  25.             $tree .= '</li><br/>';
  26.         }
  27.     }
  28.     $tree .= '</ul>';
  29.     return $tree;
  30. }
  31.  
  32. //echo(generatePageTree($datas));
  33. var_dump(generatePageTree($datas));
File Description
  • php_2
  • PHP Code
  • 07 Mar-2024
  • 933 Bytes
You can Share it: