r()
Smart version of return with an if condition as first argument
r(mixed $condition, mixed $value, mixed $alternative = null): mixed
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| $conditionrequired | mixed |
no default value | |
| $valuerequired | mixed |
no default value | The string to be returned if the condition is true |
| $alternative | mixed |
null
|
An alternative string which should be returned when the condition is false |
Return type
mixed
Examples
The following example will print odd:
<?php echo r((5 % 2 === 0), 'even', 'odd') ?>