The null coalescing operator(??) can be used in PHP for accessing array elements and assigning default values when a key does not exist or its value is null.
Using ?? is a safe way to work with arrays since it does not modify the original array; it only returns a value.
The null coalescing operator helps write cleaner and safer code for arrays avoiding verbose isset() checks.

The above code can be written like:

A much less verbose alternative for sure.
Accessing Array Elements with Default Values
We can use the null coalescing operator to check if an array has a key and assign a default one if it doesn’t.
Let’s see some examples:
In the previous example we looked at an array of recipes. We can access a recipe with bracket notation provided that it has been declared and initiated. We set a message as a default value if the recipe is not in the array.
Here is what we get in the former case:

And now what we get in the later:

Had we not used the null coalescing operator, the result in the latter case would be a Warning.

Updating Array Values
We can use the nullish coalescing assignment operator ??=, introduced in PHP 7.4, to update an array with a default value if a key doesn’t exist.

Had we used the null coalescing operator alone, wouldn’t set the ‘phone’ element in the array.

Our code simply generates a return value

To actually add a new key-value pair to an array, we must explicitly set the value.
The nullish coalescing operator assignment is a more compact syntax of this assignment.
Chaining Multiple Array Keys
Using this operator, keys are checked sequentially, in the given order.

Here, country and state are ignored and city is returned.
Order of checking plays a crucial role since the first element checked in the chain is the one that will be returned.

Conclusion
The null coalescing operator is very helpful regarding arrays when we are not sure if an index exists in the array.