mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Improve example code
This commit is contained in:
parent
51f92dd1e5
commit
33dc3a62be
@ -18,13 +18,17 @@ echo $arr["b"];
|
||||
|
||||
You can use the null coalesce operator to provide a default value in the event the array offset doesn’t exist:
|
||||
|
||||
```
|
||||
```php
|
||||
<?php
|
||||
|
||||
echo $arr["b"] ?? 0;
|
||||
```
|
||||
|
||||
Alternatively, you can ensure that the array offset always exists:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
if (rand(0, 1)) {
|
||||
$arr = ["a" => 1, "b" => 2];
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user