I have the following(json) object:
$obj = json_decode(\'{
\"Group1\": {
\"Blue\": {
\"Round\": [
\"Harold\",
Here's my take with a generator function:
function paths(array $a)
{
// if first item is an array, recurse
if (is_array(reset($a))) {
foreach ($a as $k => $v) {
foreach (paths($v) as $path) {
// yield "key - subpath"
yield sprintf('%s - %s', $k, $path);
}
}
} else {
// yield leaf
yield sprintf('(%s)', implode(', ', $a));
}
}
foreach (paths($obj) as $path) {
printf("%s\n", $path);
}
Try it online.