@ -90,26 +90,24 @@ For instance:
|
|||||||
|
|
||||||
## Ternary Operators
|
## Ternary Operators
|
||||||
|
|
||||||
Another option to consider when using short If/Else statements is the ternary operator.
|
Another important option to consider when using short If/Else statements is the ternary operator.
|
||||||
|
|
||||||
For instance:
|
```php
|
||||||
|
$statement=(condition1 ? "condition1 is true" : "condition1 is false");
|
||||||
```
|
|
||||||
<?php
|
|
||||||
|
|
||||||
$var = (condition) ? (value if true) : (value if false);
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Alternative If/Else Syntax
|
## Alternative If/Else Syntax
|
||||||
|
|
||||||
There is also an alternative syntax for control structures
|
There is also an alternative syntax for control structures
|
||||||
~~~~
|
|
||||||
|
```php
|
||||||
if (condition1):
|
if (condition1):
|
||||||
statement1;
|
statement1;
|
||||||
endif;
|
endif;
|
||||||
else
|
else
|
||||||
statement5;
|
statement5;
|
||||||
~~~~
|
```
|
||||||
|
|
||||||
For more information check out the following link:
|
For more information check out the following link:
|
||||||
<a href='http://php.net/manual/en/control-structures.alternative-syntax.php' target='_blank' rel='nofollow'>PHP Alternative syntax for control structures</a>
|
<a href='http://php.net/manual/en/control-structures.alternative-syntax.php' target='_blank' rel='nofollow'>PHP Alternative syntax for control structures</a>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user