I have an array that has some nested arrays, I would like to transform all the keys into snake case. I am trying this:
$data = collect($array)->keyBy(function ($value, $key) {
return Str::snake($key);
})->toArray();
return $data;
It is working fine, but only works for the parent array, nested arrays keep the same key:
[
"some_key" => "value",
"some_key" => [
"someKey" => "value",
"someKey" => [
"someKey" => "value"
]
]
]
What can I do? thanks.