$a = Array (' Dir1 ', ' dir2 ', ' dir3 ', ' file1 '); $b = Array (' Dir1 ', ' dir2 ', ' dir3 ', ' file2 ');//How the above array becomes the following/*array (' Dir1 ' =& Gt;array (' Dir2 ' =>array (' dir3 ' =>array (' file1 ', ' file2 ',)))); * *
Ask for an algorithm, thank you!
Reply content:
$a = Array (' Dir1 ', ' dir2 ', ' dir3 ', ' file1 '); $b = Array (' Dir1 ', ' dir2 ', ' dir3 ', ' file2 ');//How the above array becomes the following/*array (' Dir1 ' =& Gt;array (' Dir2 ' =>array (' dir3 ' =>array (' file1 ', ' file2 ',)))); * *
Ask for an algorithm, thank you!
Yes, well, I got it myself.
$a = Array (' Dir1 ', ' dir2 ', ' dir3 ', ' file1 '), function build ($tree, $arr) {if (count ($arr) = = 1) {return $arr;} $key = Array_shift ($arr), $tree [$key] = Build ($tree, $arr); return $tree;} $tree = Array ();p Rint_r (Build ($tree, $a));