Skip to content

Instantly share code, notes, and snippets.

@paulmouzas
Created February 19, 2016 14:14
Show Gist options
  • Save paulmouzas/e96675e13927841395e0 to your computer and use it in GitHub Desktop.
Save paulmouzas/e96675e13927841395e0 to your computer and use it in GitHub Desktop.
<?php
$tree = array(
"name" => "A", "child" => array(
"name" => "B", "child" => array(
"name" => "C", "child" => Null
),
),
);
function collect($node, $result=[]) {
array_push($result, $node["name"]);
if (!$node["child"]) {
return $result;
}
$result = collect($node["child"], $result);
return $result;
}
$result = collect($tree);
print_r($result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment