note 46666 deleted from language.operators.comparison by crell

From: Date: Wed, 30 Mar 2022 21:52:38 +0000
Subject: note 46666 deleted from language.operators.comparison by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217797@lists.php.net to get a copy of this message
Note Submitter: hiroh2k at yahoo dot com ---- if you want to use the ?: operator, you should be careful with the precedence. Here's an example of the priority of operators: <?php echo 'Hello, ' . isset($i) ? 'my friend: ' . $username . ', how are you doing?' : 'my guest, ' . $guestusername . ', please register'; ?> This make "'Hello, ' . isset($i)" the sentence to evaluate. So, if you think to mix more sentences with the ?: operator, please use always parentheses to force the proper evaluation of the sentence. <?php echo 'Hello, ' . (isset($i) ? 'my friend: ' . $username . ', how are you doing?' : 'my guest, ' . $guestusername . ', please register'); ?> for general rule, if you mix ?: with other sentences, always close it with parentheses.

« previous php.notes (#217797) next »