(Condition) ? (Statement1) : (Statement2);
<?php
$marks=40;
print ($marks>=40) ? "pass" : "Fail";
?>
$result = $condition ? 'foo' : 'bar';
// Both ternary and if/else returns the same result
// ternary
$result = $condition ? 'foo' : 'bar';
// if/else
if ($condition) {
$result = 'foo'
} else {
$result = 'bar'
}
echo $color = $color ?? 'red'; //if value not exists then assign to them.
(conditional) ? (execute this when true) : (execute this when false);
# example
<?php
$age = 20;
print ($age >= 18) ? "Adult" : "Not Adult";
?>
# output
Adult
print ($marks>=40) ? "pass" : "Fail";
<?php
$x=4;
$y=3;
if(x>y)?echo"X is large": echo "y is large";
?>
$if = function($test, $true, $false)
{
return $test ? $true : $false;
};
echo "class='{$if(true, 'abc', 'def')}'";
$customer->user->fullName ?? ''
$customer->user->fullName ? $customer->user->fullName : ''
isset($customer->user->fullName) ? $customer->user->fullName : ''
Code Example |
---|
Php :: Web servers supported by php |
Php :: set config key dynamic laravel |
Php :: php print fetch |
Php :: lookup token information in vault |
Php :: array_push php |
Php :: PHP exif_read_data() |
Php :: save big data with laravel |
Php :: wp_mail multiple recipients |
Php :: create a button add in laravel |
Php :: php if null then 0 |
Php :: set border phpoffice phpexcel |
Php :: php print html code |
Php :: how to add image in wordpress theme |
Php :: laravel test filter |
Php :: laravel pluck multiple columns |
Php :: array_diff php |
Php :: php sms sending script |
Php :: php undefined offset |
Php :: laravel make:action |
Php :: laravel crud example |
Php :: guzzle login example |
Php :: country list laravel |
Php :: send gmail |
Php :: php array |
Php :: laraodck imagick |
Php :: Best testing tools for php |
Php :: laravel 8 logout 419 page expired |
Php :: string operator in php |
Php :: apache 2 |
Php :: laravel route not found |