Answer the question
In order to leave comments, you need to log in
Dot notation in working with arrays in laravel. Is it worth using?
There are many helpers in laravel related to working with arrays.
One group of these helpers is dedicated to dot notations (eg arr::has, arr::get, etc.).
Basically, the appearance of the code becomes more readable, as it seems to me:
Arr::has($array, ['product.data.price', 'product.data.name']);
isset($array['product']['data']['price'], $array['product']['data']['name']);
Answer the question
In order to leave comments, you need to log in
Purely my IMHO. This is not a standard.
If you can not use helpers - in principle, you should do it, but this applies to operators in the language ( []
), rather than standard functions (which is isset()
).
So that:
Arr::has($array, 'nested.key') а не isset($array['nested']['key'])
Arr::get($array, 'nested.key') а не isset($array['nested']) ? ($array['nested']['key'] ?? null) : null
$array['key'] ?? null а не Arr::get($array, 'key')
$array['key'] ?? doSomething() а не Arr::get($array, 'key', fn () => doSomething())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question