Convert 2d array into 3d with PHP

kSherrylKilianm

New Member
There are simple 2d array with some sort of tree like this:
  • node1
    • node2node3
It's structure is:\[code\]array( array ( 'id' : 1, 'pid': 0, 'title' : 'node1', 'level' : 1 ), array ( 'id' : 2, 'pid': 1, 'title' : 'node2', 'level' : 2 ), array ( 'id' : 3, 'pid': 2, 'title' : 'node3', 'level' : 3 ),)\[/code\]Is there solutions with PHP to convert this array into:\[code\]array( array ( 'id' : 1, 'title' : 'node1', 'child' : array ( 'id' : 2, 'title' : 'node2', 'child' : array ( 'id' : 3, 'title' : 'node3', ), ), ) ...)\[/code\]
 
Back
Top