note 109869 deleted from language.operators.logical by danbrown
| From: | danbrown@php.net | Date: | Fri, 31 Aug 2012 15:37:29 +0000 |
| Subject: | note 109869 deleted from language.operators.logical by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190311@lists.php.net to get a copy of this message | ||
Note Submitter: jordan at avacweb dot com
----
I've noticed some people here (or maybe person) mentioned about how you can't use these
operators to assign a "default" in a similar to you would in the likes of javascript. Eg
var x = 0 || 1; x would equal 1.
It IS possible to do this very simply:
<?php
$a = false;
$a or ($a = 'default value');
echo $a; // 'default value'
?>
This is allows you to perform the same javascript-like evaluation.
Of course, in PHP, this wouldn't be needed in a function since you can declare default values
for arguments anyway.