note 120847 added to control-structures.alternative-syntax

From: Date: Tue, 21 Mar 2017 13:45:47 +0000
Subject: note 120847 added to control-structures.alternative-syntax
Groups: php.notes 
Request: Send a blank email to php-notes+get-208938@lists.php.net to get a copy of this message
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' ?> ---- Server IP: 72.52.91.14 Probable Submitter: 194.242.159.242 ---- Manual Page -- http://php.net/manual/en/control-structures.alternative-syntax.php Edit -- https://master.php.net/note/edit/120847 Del: integrated -- https://master.php.net/note/delete/120847/integrated Del: useless -- https://master.php.net/note/delete/120847/useless Del: bad code -- https://master.php.net/note/delete/120847/bad+code Del: spam -- https://master.php.net/note/delete/120847/spam Del: non-english -- https://master.php.net/note/delete/120847/non-english Del: in docs -- https://master.php.net/note/delete/120847/in+docs Del: other reasons-- https://master.php.net/note/delete/120847 Reject -- https://master.php.net/note/reject/120847 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#208938) next »