get path of Array (PHP)

Posted by Kawah Grafis on Stack Overflow See other posts from Stack Overflow or by Kawah Grafis
Published on 2011-01-17T07:34:23Z Indexed on 2011/01/17 7:53 UTC
Read the original article Hit count: 179

Filed under:

i have an array input like this ..

Array
(
    [0] => Array
        (
            [0] => 42
        )

    [**42**] => Array
        (
            [0] => 12
            [1] => 14
        )

    [**14**] => Array
        (
            [0] => 317
        )

    [317] => Array
        (
            [0] => 319
        )

    [**12**] => Array
        (
            [0] => 306
            [1] => 307
        )

    [307] => Array
        (
            [0] => 311
        )

    [306] => Array
        (
            [0] => 309
        )
)

and i want to get result array like bellow :

$paths[]=array(42,12,306,309);

$paths[]=array(42,12,307,311);

$paths[]=array(42,14,317,319);

see array input

  • root in array input = 42 (index of array 0)
  • 42 have child = 12, 14
  • 12 have child = 306, 307
  • 14 have child = 317
  • 306 have child = 309
  • 307 have child = 311
  • 317 have child = 319

like this..

and output array insert into $paths

$paths[0]=array(42,12,306,309);

$paths[1]=array(42,12,307,311);

$paths[2]=array(42,14,317,319);

© Stack Overflow or respective owner

Related posts about php