e()
Smart version of echo with an if condition as first argument
Parameters
Name | Type | Default | Description |
---|---|---|---|
$condition * | mixed |
– | |
$value * | mixed |
– | The string to be echoed if the condition is true |
$alternative | mixed |
null |
An alternative string which should be echoed when the condition is false |
Example
With fallback if condition is false:
Only echo something when condition is true:
Note:
e()
is a function, therefore the parameters you pass to this function have already been evaluated when you pass them to the method. Trying to do something like the following will therefore throw an error:
For cases like this, you have the following options, depending on whether you need a fallback value or not: