Created A Nested Array Help

Hi every body
I want to create an array which have the following roles
1- nested array with 4 level depth
2- each parent have only 2 children
3- if parent is P and 2children is C1 and C2 then :
C1 = P 2
C2 = P
2 + 1
eg binary tree nested array
how could i code it using function with input id
eg: function createArray($id){}