PHP7 introduced the null coalesce operator (??) which will suppress errors for the missing intermediate keys. So, this will work without errors/warnings:
$phone=$orders[0]['customer']['phone']??null;
The Laravel framework in PHP also has array helpers which allow you to access values using "dot" notation:
$phone=array_get($orders,'0.customer.phone');
You can pass a third value to use as the default if it doesn't exist, but the default is null without it.
This helper function is a shortcut to access the Arr::get() method mentioned by Suhayb Alghutaymil.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
PHP7 introduced the null coalesce operator (
??
) which will suppress errors for the missing intermediate keys. So, this will work without errors/warnings:The Laravel framework in PHP also has array helpers which allow you to access values using "dot" notation:
You can pass a third value to use as the default if it doesn't exist, but the default is
null
without it.This helper function is a shortcut to access the
Arr::get()
method mentioned by Suhayb Alghutaymil.