Created
August 14, 2014 20:43
-
-
Save esommer/deae82de2fb0118c622a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$tree = [ | |
["field" => "A", "nested" => [ | |
["field" => "B", "nested" => []] | |
]], | |
["field" => "C", "nested" => [ | |
["field" => "D", "nested" => [ | |
["field" => "E", "nested" => []] | |
]], | |
["field" => "F", "nested" => []] | |
]] | |
]; | |
$result = [ | |
["field" => "A", "nested" => [ | |
["field" => "B", "nested" => []] | |
]], | |
["field" => "C", "nested" => [ | |
["field" => "D", "nested" => [ | |
["field" => "E", "nested" => []] | |
]]]], | |
["field" => "C", "nested" => [ | |
["field" => "F", "nested" => []] | |
]] | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know how to write PHP, but here is some Ruby-like pseudocode:
If the variable
trees
is what you laid out above under$tree
and you do:By the end the variables
complete_paths
should contain:[[A,B], [C,D,E], [C,F]]
... I think.