note 128059 added to function.list
| From: | nek dot dev at gmail dot com | Date: | Tue, 27 Dec 2022 22:13:40 +0000 |
| Subject: | note 128059 added to function.list | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220014@lists.php.net to get a copy of this message | ||
It can be convenient to specify a default value in case an element is missing in the list. You can
use operator + for this:
<?php
$someArray = ['color' => 'orange'];
['color' => $color, 'size' => $size] = $someArray + ['color'
=> null, 'size' => null];
?>
This will avoid the warning
Undefined array key "size" you would encounter
otherwise.
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.158.213 (proxied: 2a01:e0a:a51:3de0:2d5f:3a35:e274:18e0)
----
Manual Page -- https://php.net/manual/en/function.list.php
Edit -- https://main.php.net/note/edit/128059
Del: integrated -- https://main.php.net/note/delete/128059/integrated
Del: useless -- https://main.php.net/note/delete/128059/useless
Del: bad code -- https://main.php.net/note/delete/128059/bad+code
Del: spam -- https://main.php.net/note/delete/128059/spam
Del: non-english -- https://main.php.net/note/delete/128059/non-english
Del: in docs -- https://main.php.net/note/delete/128059/in+docs
Del: other reasons-- https://main.php.net/note/delete/128059
Reject -- https://main.php.net/note/reject/128059
Search -- https://main.php.net/manage/user-notes.php