From 0b78a32686bb45aa0aba9bc5c4ad61fc16b4e1b7 Mon Sep 17 00:00:00 2001 From: Neil Masters Date: Wed, 12 Mar 2014 13:27:40 +0000 Subject: [PATCH] Update The-Basics.md Adding a suggested change to ternary operators where its not actually necessary to use them but is commonly seen. --- pages/The-Basics.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pages/The-Basics.md b/pages/The-Basics.md index f6f3484..68f2d52 100644 --- a/pages/The-Basics.md +++ b/pages/The-Basics.md @@ -304,6 +304,19 @@ vs. $a = 5; 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 %} * [Ternary operators](http://php.net/manual/en/language.operators.comparison.php)