I'm working on documenting an API, so I am parsing example XML/JSOn output and need to find all the named keys to add definitions. So, I have an array like this:
$array = [
"user" => [
"name" => "John",
"email" => "[email protected]",
"products" => [
0 => "product A",
1 => "product B"
],
"files" => [
"logo" => "/path/logo.jpg",
"profile" => "/path/profile.jpg"
]
],
"offer" => [
0 => "My offer"
]
];
And I want to extract all the keys from the array, no matter its depth, and get an output akin to:
$keys = [
0 => ["user"],
1 => ["user", "name"],
2 => ["user", "email"],
3 => ["user", "products"],
4 => ["user", "files"],
5 => ["user", "files", "logo"],
6 => ["user", "files", "profile"],
7 => ["offer"]
];
Note that keys that are numeric are ignored, only named keys are included in the hierarchy. I have googled and tried to find something that does this, but I've come up blank. I have tried some function chaining but I just can't wrap my head around the loops and returns correctly. Any help is appreciated!