I have multidimensional array like this. It is in var_dump() formatting.
array(1) {
[4]=>
array(1) {
[2]=>
array(1) {
[5]=>
array(1) {
[1]=>
array(1) {
[3]=>
array(1) {
[6]=>
array(0) {
}
}
}
}
}
}
}
aka $multiArray and i want to get all keys from it and set them to get array like this.
[0=>4, 1=>2, 2=>5, 3=>1, 4=>3, 5=>6] aka **$keysArray**.
Tried like this.
foreach( new \RecursiveIteratorIterator(
new \RecursiveArrayIterator(**$multiArray**),
\RecursiveIteratorIterator::SELF_FIRST)
as $key => $value) {
**$keysArray[]** = $key;
}
also this.
function array_keys_multi(array $array) {
$keys = [];
foreach ($array as $key => $value) {
$keys[] = $key;
if (is_array($value)) {
$keys = array_merge($keys, $this->array_keys_multi($value));
}
}
return $keys;
}
but both of them returns incorrect data. How can i get all keys?