Skip to content
Advertisement

How to show parent and child items form array in php

I am new at php. Maybe a simple question.. I want to make parent->child view. I have an array like this: With key id and key parent.

How to draw in cycle correct structure? Maybe at first I need to create function for creating the tree ?

JavaScript

Advertisement

Answer

Cycle through the source array $arr to detect records that have a parent (not null). When a child record is found, push it into the parent.

JavaScript

demo

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement