The entry in the arrays by keys of the form data.items.cars?

Is there a way easy and beautiful way to send someone a view key data.items.cars, the value of the form

[
['id'=>1],
['id'=>2],
['id'=>3]
]


and get to the exit
[
 'data' => [
 'items' => [
 'cars' => [
['id'=>1],
['id'=>2],
['id'=>3]
]
]
]
]
July 2nd 19 at 18:22
2 answers
July 2nd 19 at 18:24
Why?
Maybe it's worth to translate it all into objects? Code will become more readable, easier to refactor, and as a bonus auto-completion in the ide
the client simply requests the data according to certain aliases and sends a structure, like the example by which they should be expanded. - mona commented on July 2nd 19 at 18:27
It's something like the V in MVC, but it is configured from the client... - mona commented on July 2nd 19 at 18:30
July 2nd 19 at 18:26
funciton to_nice_array($key, $items) {
 $key_parts = explode('.', $key);
 $key_parts = array_reverse($key_parts);
 $result = $items;
 foreach ($key_parts as $key_part) {
 $result = array($key_part => $result);
}
 return $result;
}
I'm telling you - easily and beautifully.. so I will write ;) - mona commented on July 2nd 19 at 18:29

Find more questions by tags PHP