RE: [PHP] what do '?' and ':' do?
| From: | Chris W. Parker | Date: | Mon, 17 May 2004 19:43:58 +0000 |
| Subject: | RE: [PHP] what do '?' and ':' do? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-186425@lists.php.net to get a copy of this message | ||
Radek Zajkowski <mailto:radek.z@engage-learn.com>
on Monday, May 17, 2004 12:38 PM said:
> $module_dir = ($module == "")
> ? ""
> : $module."/";
>
> what does the semicolon and the question mark do?
<?php
if ($module == "")
{
$module_dir = "";
}
else
{
$module_dir = $module."/";
}
?>
i think it's called a ternary operator. usually i write it all on one
line like so:
<?php
$module_dir = ($module == "") ? "" : $module."/" ;
?>
hth!
chris.