Answers for "short if phpo"

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

shorthand if php

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

Browse Popular Code Answers by Language