php เขียนเงื่อนไข if else แบบสั้น


หน้าแรก PHP MySQL เกร็ดความรู้ php เขียนเงื่อนไข if else แบบสั้น
การเขียนตรวจสอบเงื่อนไขแบบปกติในภาษา php


  Code
<?php
$a=1;
$b=2;
if ($a > $b) {
echo "a is bigger than b";
} else {
echo "a is smaller than b";
}
?>



ต่อไปมาดูแบบสั้นบ้างจากโค้ดด้านบน



  Code
<?php
$a=1;
$b=2;
echo $a>$b ? 'a is bigger than b' : 'a is smaller than b';
?>



- See more at: http://phplike.blogspot.com/2014/01/php-if-else.html#sthash.DrgbapSn.dpuf

ขึ้นไปด้านบน