note 106291 modified in language.operators.logical by danbrown
| From: | danbrown@php.net | Date: | Tue, 25 Oct 2011 21:33:48 +0000 |
| Subject: | note 106291 modified in language.operators.logical by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-184123@lists.php.net to get a copy of this message | ||
A handy way to set a variable using or
<?php
if ($foo) {
$foo = 5;
}
// Can be replaced with
$foo or $foo = 5;
?>
I use this often for setting variables in functions with optional parameters.
<?php
function foobar($a = null, $b = null) {
$a or $a = 10;
$b or $b = 20;
//...
}
--was--
A handy way to set a variable using or
<?php
if ($foo) {
$foo = 5;
}
// Can be replaced with
$foo or $foo = 5;
?>
I use this often for setting variables in functions with optional parameters.
<?php
function foobar($a = null, $b = null) {
$a or $a = 10;
$b or $b = 20;
...
}
http://php.net/manual/en/language.operators.logical.php