Php中的三元运算符

代码示例

10
0

php三元运算符

(Condition) ? (Statement1) : (Statement2);
5
0

php中的三元运算符

<?php
$marks=40;
print ($marks>=40) ? "pass" : "Fail";
?>
3
0

php三元

$result = $condition ? 'foo' : 'bar';
3
0

php三元

$result = $condition ? 'foo' : 'bar';
1
0

php中的三元

print ($marks>=40) ? "pass" : "Fail";
1
0

php三元运算符

// Both ternary and if/else returns the same result

// ternary
$result = $condition ? 'foo' : 'bar';

// if/else
if ($condition) {
    $result = 'foo' 
} else {
    $result = 'bar'
}
1
0

?? 三操作员在php

echo $color = $color ?? 'red';	//if value not exists then assign to them.
0
0

三操作人员对三个条件中的php

$foo = your_value;
$bar = ($foo == 1) ? "1" : (($foo == 2)  ? "2" : "other");
echo $bar;
0
0

三操作员在php

<?php
  $x=4;
  $y=3;
  if(x>y)?echo"X is large": echo "y is large";

 ?>

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................