Created
February 5, 2019 14:42
-
-
Save sweikenb/1e8dc135a3e0466e15af3aaf5ea173d6 to your computer and use it in GitHub Desktop.
PHP array practice (recursion)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Conditions: | |
*********************************************************************************************************************** | |
* | |
* Do not modify or edit this file/array -> include it into your working file and use the $tree array as it is. | |
* | |
* | |
* Tasks: | |
*********************************************************************************************************************** | |
* | |
* 1. Count the number of nodes of this tree | |
* 2. Print the tree on the terminal prefixed with a "-" for each level of the corresponding node (example below) | |
* | |
* | |
* Example for taks 2 | |
*********************************************************************************************************************** | |
* | |
* Node [...] | |
* - Node [...] | |
* - Node [...] | |
* -- Node [...] | |
* -- Node [...] | |
* --- Node [...] | |
* -- Node [...] | |
* --- Node [...] | |
* ---- Node [...] | |
* - Node [...] | |
* -- Node [...] | |
* - Node [...] | |
* | |
*/ | |
$tree = [ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [ | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
[ | |
'name' => 'node-' . __LINE__, | |
'nodes' => [], | |
], | |
], | |
], | |
], | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment