From adff75fc958bd5044f779b49166ec6d4f97b046f Mon Sep 17 00:00:00 2001 From: Evgeny Chernyavskiy Date: Sat, 3 Oct 2015 16:44:04 -0400 Subject: [PATCH] Add an example of even more simple boolean return statement --- pages/The-Basics.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pages/The-Basics.md b/pages/The-Basics.md index 9628b60..d21e131 100644 --- a/pages/The-Basics.md +++ b/pages/The-Basics.md @@ -27,7 +27,7 @@ if (strpos('testing', 'test')) { // 'test' is found at position 0, which is i // code... } -// vs +// vs. if (strpos('testing', 'test') !== false) { // true, as strict comparison was made (0 !== false) // code... @@ -57,7 +57,7 @@ function test($a) } } -// vs +// vs. function test($a) { @@ -66,6 +66,14 @@ function test($a) } return false; // else is not necessary } + +// or even shorter: + +function test($a) +{ + return (bool) $a; +} + {% endhighlight %} * [If statements](http://php.net/control-structures.if)