note 35552 modified in control-structures.alternative-syntax by vincent
| From: | vincent@php.net | Date: | Sat, 06 Sep 2003 09:29:57 +0000 |
| Subject: | note 35552 modified in control-structures.alternative-syntax by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-55530@lists.php.net to get a copy of this message | ||
You can use a short syntax for "if"
$a = (condition) ? value if condition is true : value if condition is false;
<?php
$a = 1 ;
$b = 2 ;
$is_a_bigger = ($a > $b) ? 1 : 0 ;
echo $a_is_bigger ;
# returns 0
$a = 2 ;
$b = 1 ;
$is_a_bigger = ($a > $b) ? 1 : 0 ;
echo $is_a_bigger ;
# returns 1
?>
--was--
You can use a short syntax for "if"
$a = (condition) ? value if condition is true : value if condition is false;
<?php
$a = 1 ;
$b = 2 ;
$is_a_bigger = ($a > $b) ? 0 : 1 ;
echo $a_is_bigger ;
# returns 0
$a = 2 ;
$b = 1 ;
$is_a_bigger = ($a > $b) ? 0 : 1 ;
echo $is_a_bigger ;
# returns 1
?>
http://www.php.net/manual/en/control-structures.alternative-syntax.php