PHP Tutorial : If condition in the short way (shorthand if)

Do you know basical php if() condition right? But, my questions is : do you know the short way? If not, I will show you the diferrence,:

<?php
$a=1;
$b=3;
$c = $a+$b;
//THE SHORT WAY COMES
print $c == 3 ? "yes $c = 3" : "no $c != 3";
//THE "COMMON" WAY SAME THING


if($c ==3) {
print "yes $c = 3";
}else{
print "no $c != 3";
}
?>
This entry was posted in Basic PHP and tagged , , , , , . Bookmark the permalink.

2 Responses to PHP Tutorial : If condition in the short way (shorthand if)

  1. bogdan says:

    Would have been more useful to refer to it in its more widely-known name: shorthand if. Bit better for some google visits I mean.

  2. admin says:

    hmm didn’t know that name but I added that tag too, thanks for your time

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>