Re: a shortcut to set variable

From: Date: Tue, 12 Apr 2011 13:25:25 +0000
Subject: Re: a shortcut to set variable
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-312352@lists.php.net to get a copy of this message
At 12:47 PM +0100 4/12/11, Richard Quadling wrote:
Putting () around ternary's is a "best practise". <?php echo 'Are we ready to go? ', isset($go) ? 'Yes we are.' : 'No we are not.', ' Ready state completed', PHP_EOL; $go = true; echo 'Are we ready to go? ', isset($go) ? 'Yes we are.' : 'No we are not.', ' Ready state completed', PHP_EOL; ?> vs. <?php echo 'Are we ready to go? ' . isset($go) ? 'Yes we are.' : 'No we are not.' . ' Ready state completed' . PHP_EOL; $go = true; echo 'Are we ready to go? ' . isset($go) ? 'Yes we are.' : 'No we are not.' . ' Ready state completed' . PHP_EOL; ?> vs. <?php echo 'Are we ready to go? ' . (isset($go) ? 'Yes we are.' : 'No we are not.') . ' Ready state completed' . PHP_EOL; $go = true; echo 'Are we ready to go? ' . (isset($go) ? 'Yes we are.' : 'No we are not.') . ' Ready state completed' . PHP_EOL; ?> Don't run them just yet. Can you quickly and easily see the output?
Argg! :-) $ready = 'Are we ready to go? '; $yes = 'Yes we are.'; $no = 'No we are not.' echo($ready); echo(isset($go) ? $yes : $no); Cheers, tedd -- ------- http://sperling.com/

« previous php.general (#312352) next »