I am using PHP and I need help with a simple array task.
This is my sample array:
$arr = array(
0 => NULL,
1 => NULL,
2 => NULL,
3 => NULL,
8 => '2',
9 => '2',
10 => '2',
11 => '2',
12 => '3',
13 => '3',
14 => '8',
15 => '8',
16 => '14',
17 => '14',
18 => '14'
);
Array keys represent an ID (unique).
The values are parentIDs , that is, the identifier of the parent "node". NULLmeans there is no parent identifier (i.e. the first dimension of the new array).
Now I need to create a new multidimensional array that has all the children under their parent identifiers. (Perhaps this sounds very confusing, sorry for the lack of descriptive abilities. Here is an example below that should make everything clearer)
, :
$arr = array(
0 => array(),
1 => array(),
2 => array(
8 => array(
14 => array(
16 => array(),
17 => array(),
18 => array()
),
15 => array()
),
9 => array(),
10 => array(),
11 => array()
),
3 => array(
12 => array(),
13 => array()
)
);
, () s, , , , , !