Update The-Basics.md

Adding a suggested change to ternary operators where its not actually necessary to use them but is commonly seen.
This commit is contained in:
Neil Masters
2014-03-12 13:27:40 +00:00
parent 248aa25dfc
commit 0b78a32686

View File

@@ -304,6 +304,19 @@ vs.
$a = 5; $a = 5;
return ($a == 5) ? 'yay' : 'nope'; // this example will return 'yay' return ($a == 5) ? 'yay' : 'nope'; // this example will return 'yay'
It should be noted to save confusion that you do not need to use a ternary operator for returning a boolean value. An example of this would be.
$a = 3;
return ($a == 3) ? true : false; // Will return true or false if $a == 3
vs
$a = 3;
return ($a == 3); // Will return true or false if $a == 3
This can also be said for all operations(===, !==, !=, == etc).
{% endhighlight %} {% endhighlight %}
* [Ternary operators](http://php.net/manual/en/language.operators.comparison.php) * [Ternary operators](http://php.net/manual/en/language.operators.comparison.php)