Logo

Programming-Idioms

History of Idiom 17 > diff from v42 to v43

Edit summary for version 43 by ancarda:
[PHP] Format code snippet to PSR-12

Version 42

2019-09-27, 08:50:51

Version 43

2019-09-27, 10:18:08

Idiom #17 Create a Tree data structure

The structure must be recursive. A node may have zero or more children. A node has access to children nodes, but not to its parent.

Idiom #17 Create a Tree data structure

The structure must be recursive. A node may have zero or more children. A node has access to children nodes, but not to its parent.

Code
class Tree {
    public $children = [];
    public $data;
    
    public function __construct($data, $children) {
        $this->data = $data;
        $this->children = $children;
    }
    
}
Code
class Tree
{
    public $children = [];
    public $data;
    
    public function __construct($data, $children)
    {
        $this->data = $data;
        $this->children = $children;
    }
}
Demo URL
https://3v4l.org/GIgDC
Demo URL
https://3v4l.org/GIgDC