1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00

Improve example code

This commit is contained in:
Matthew Brown 2020-03-20 19:19:24 -04:00
parent 51f92dd1e5
commit 33dc3a62be

View File

@ -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 doesnt exist: You can use the null coalesce operator to provide a default value in the event the array offset doesnt exist:
``` ```php
<?php
echo $arr["b"] ?? 0; echo $arr["b"] ?? 0;
``` ```
Alternatively, you can ensure that the array offset always exists: Alternatively, you can ensure that the array offset always exists:
```php ```php
<?php
if (rand(0, 1)) { if (rand(0, 1)) {
$arr = ["a" => 1, "b" => 2]; $arr = ["a" => 1, "b" => 2];
} else { } else {