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.
Result of php executing
Full code of php_2.php
- <?php
- //$input['vs_portal'] = true;
- if (isset($input['vs_portal']) && ($input['vs_portal'] === true)) {
- $input['vs_portal'] = true;
- }
- // $bear = $input['vs_portal'] ?: false;
- $datas = array(
- array('id' => 1, 'parent_id' => 0, 'name' => (isset($input['vs_portal']))),
- array('id' => 2, 'parent_id' => 1, 'name' => $bear),
- );
- function generatePageTree($datas, $parent = 0, $depth = 0) {
- $ni=count($datas);
- if($ni === 0 || $depth > 1000) return ''; // Make sure not to have an endless recursion
- $tree = '<ul>';
- for($i=0; $i < $ni; $i++){
- if($datas[$i]['parent_id'] == $parent){
- $tree .= '<li>';
- $tree .= $datas[$i]['name'];
- $tree .= generatePageTree($datas, $datas[$i]['id'], $depth+1);
- $tree .= '</li><br/>';
- }
- }
- $tree .= '</ul>';
- return $tree;
- }
- //echo(generatePageTree($datas));
- var_dump(generatePageTree($datas));
File Description
- php_2
- PHP Code
- 07 Mar-2024
- 933 Bytes
You can Share it:
Latest PHP Pastes