I want to create flat array from nested array, like this one:
[0]=>Array(
"id"=>1,
"positions">Array(
[0]=>Array(
"id"=>2
),
[1]=>Array(
"id"=>3
"positions"=>Array(
[0]=>Array(
"id"=>4
)
)
)
to something like this:
[0]=>Array(
"id"=>1,
"parent_id"=>0
),
[1]=>Array(
"id"=>2,
"parent_id"=>1
),
[2]=>Array(
"id"=>3,
"parent_id"=>1
),
[3]=>Array(
"id"=>4,
"parent_id"=>3
)
I don't have parent_id in nested structure, so all the trick is to "ride" trough the nested array, and add 'parent_id', base on id from parent node. I know how to flat the array, but I need parent_id information.
Use this code
Your array must be of this structure
Then call the function
generateArray()
,