note 117218 added to language.operators.logical
| From: | 4077 | Date: | Mon, 04 May 2015 18:20:38 +0000 |
| Subject: | note 117218 added to language.operators.logical | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202425@lists.php.net to get a copy of this message | ||
Assign a value to a variable if it isn't defined
<?php
isset($x) || $x = 123;
print $x; // 123
?>
instead of:
<?php
if ( !isset($x)) {
$x = 123;
}
// or
$x = isset($x) ? $x : 123;
// or
$x = isset($x) ?: 123;
----
Server IP: 72.52.91.14
Probable Submitter: 178.219.32.39
----
Manual Page -- http://php.net/manual/en/language.operators.logical.php
Edit -- https://master.php.net/note/edit/117218
Del: integrated -- https://master.php.net/note/delete/117218/integrated
Del: useless -- https://master.php.net/note/delete/117218/useless
Del: bad code -- https://master.php.net/note/delete/117218/bad+code
Del: spam -- https://master.php.net/note/delete/117218/spam
Del: non-english -- https://master.php.net/note/delete/117218/non-english
Del: in docs -- https://master.php.net/note/delete/117218/in+docs
Del: other reasons-- https://master.php.net/note/delete/117218
Reject -- https://master.php.net/note/reject/117218
Search -- https://master.php.net/manage/user-notes.php