note 120847 deleted from control-structures.alternative-syntax by salathe
| From: | salathe@php.net | Date: | Mon, 21 Sep 2020 14:35:36 +0000 |
| Subject: | note 120847 deleted from control-structures.alternative-syntax by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215214@lists.php.net to get a copy of this message | ||
Note Submitter: howeson dot h at gmail dot com
----
The following if statement works if you want to do a shorthand if statement and would rather use
echo (or any other function) instead of print:
<?php
$value = 'Jesus';
echo isset($value) ? $value : ''; // Would return 'Jesus'
?>
The issue with this is that you must also declare a value to be printed if the statement returns
false (after the colon).
An example of an if else statement would be:
<?php
echo isset($value) ? $value : 'Value is not set'; // Would return 'Value is not
set'
$value = 'Jesus';
echo isset($value) ? $value : 'Value is not set'; // Would return 'Jesus'
?>