Answers for "php shorthand if"

PHP
3

php short if

<?php
$v = 1;

$r = (1 == $v) ? 'Yes' : 'No'; // $r is set to 'Yes'
$r = (3 == $v) ? 'Yes' : 'No'; // $r is set to 'No'

echo (1 == $v) ? 'Yes' : 'No'; // 'Yes' will be printed

// and since PHP 5.3
$v = 'My Value';
$r = ($v) ?: 'No Value'; // $r is set to 'My Value' because $v is evaluated to TRUE

$v = '';
echo ($v) ?: 'No Value'; // 'No Value' will be printed because $v is evaluated to FALSE
?>
Posted by: Guest on July-24-2021
3

php shorthand if

$is_admin = ($user['permissions'] == 'admin') ? true : false;
Posted by: Guest on May-15-2020
2

php ternary shorthand

$y = $x ? "true" : "false";
Posted by: Guest on May-25-2020
2

php if short form

<?php echo ($qte > 0) ? $qte : 0; ?>
Posted by: Guest on November-14-2020

Browse Popular Code Answers by Language