Return to Snippet

Revision: 49417
at July 21, 2011 20:30 by theworldofdan


Initial Code
<?php
// Shorthand notation for if/else statements, basic example below:
$myGender == 'male' ? 'i am male' : 'I am female'
?>

<!-- can be used inline, such as: -->
<select name="gender">
	<option value="female" <?php echo ($myGender == 'female' ? 'selected' : ''); ?>>Female</option>
	<option value="male" <?php echo ($myGender == 'male' ? 'selected' : ''); ?>>Male</option>
</select>

<?php
// it can also be used to assign a value to a variable:
$is_admin = ($user['permissions'] == 'admin' ? true : false);
// or:
$x = ($myvalue == 10) ? 'the value is 10' : 'the value is not 10';
?>

Initial URL

                                

Initial Description

                                

Initial Title
Shorthand IF/ELSE statements

Initial Tags

                                

Initial Language
PHP