skip to Main Content

JSON Tree PHP using a recursive function

The problem is that each child element is bound to each parent element, which is why everything is duplicated <?php $json = '[ {"id":3633,"name":"Mobile phones and accessories","left":1,"right":18,"level":1,"elements":0}, {"id":3638,"name":"Mobile phones","left":2,"right":3,"level":2,"elements":174}, {"id":21396,"name":"Tablets","left":19,"right":24,"level":1,"elements":0}, {"id":21450,"name":"Some Tablets","left":20,"right":21,"level":2,"elements":8} ]'; $data = json_decode($json, true); function buildTree($data, $level…

VIEW QUESTION
Back To Top
Search