Hello guys.

Got an array

PHP Code:
Array
(
    [
cats] => Array
        (
            [
1] => Array
                (
                    [
id] => 1
                    
[name] => women
                    
[pID] => 0
                
)

            [
2] => Array
                (
                    [
id] => 2
                    
[name] => fashion
                    
[pID] => 1
                
)

            [
3] => Array
                (
                    [
id] => 3
                    
[name] => sport
                    
[pID] => 2
                
)

            [
4] => Array
                (
                    [
id] => 4
                    
[name] => home
                    
[pID] => 1
                
)

            [
5] => Array
                (
                    [
id] => 5
                    
[name] => men
                    
[pID] => 4
                
)

        )



using

PHP Code:
$arr = array();
   foreach(
$catsL['cats'] as $k => $c) {
     if((
$c['pID']) > 0) {
         
$array[$c['pID']]['children'][] = $c;
     } else {
         
$array[$c['id']] = $c;
     }

Want to get array like:

item/id/parent

item-1 / 2 / 0
item-1 / 3 / 2 - child of element with id 2
item-1 / 4 / 3 - child of element with id 3


Got:

PHP Code:
Array
(
    [
0] => Array
        (
            [
id] => 1
            
[name] => women
            
[pID] => 0
            
[children] => Array
                (
                    [
0] => Array
                        (
                            [
id] => 2
                            
[name] => fashion
                            
[pID] => 1
                        
)

                    [
1] => Array
                        (
                            [
id] => 4
                            
[name] => home
                            
[pID] => 1
                        
)

                )

        )

    [
1] => Array
        (
            [
children] => Array
                (
                    [
0] => Array
                        (
                            [
id] => 3
                            
[name] => sport
                            
[pID] => 2
                        
)

                )

        )

    [
2] => Array
        (
            [
children] => Array
                (
                    [
0] => Array
                        (
                            [
id] => 5
                            
[name] => men
                            
[pID] => 4
                        
)

                )

        )


Childs getting inserted as new elements of 1st level array not as child.

Any clues?