r()
Smart version of return with an if condition as first argument
r(mixed $condition, mixed $value, mixed $alternative = null): mixed|null
Parameters
Name | Type | Default | Description |
---|---|---|---|
$condition * | mixed |
– | |
$value * | mixed |
– | 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
|null
Example
The following example will print odd
:
<?php echo r((5 % 2 === 0), 'even', 'odd') ?>