<?php
$array = [
'a' => [
'a' => [
'a' => null,
'b' => null
],
'b' => [
'a' => null,
'b' => null
]
],
'b' => [
'a' => [
'a' => null,
'b' => null
],
'b' => [
'a' => null,
'b' => null
]
]
];
function getKeyPaths(array $array, string $prefix = ''): string
{
return implode(
',',
array_map(
fn($k, $v) => is_array($v) ? getKeyPaths($v, "$prefix$k") : "$prefix$k",
array_keys($array), $array
)
);
}
var_export(getKeyPaths($array));
preferences:
52.08 ms | 407 KiB | 5 Q