I am using Laravel 5.6. I want a function that returns only the specified key / value pairs from the given array using the dot notation.
For example:
$array = [
'name' => [
'first' => 'John',
'last' => 'Smith'
],
'price' => 100,
'orders' => 10
];
$slice = someFunc($array, ['name.first', 'price']);
should return:
[
'name' => [
'first' => 'John'
],
'price' => 100,
]
The closest function that does this is in Laravel that I can find is the array_only
function:
https://laravel.com/docs/5.6/helpers#method-array-only
However, it does not support the dot notation (unlike some other Laravel functions).
How can I achieve this?