Source: levelup.gitconnected.com

PHP 7.x — P5: Truthy Bools

Category: PHP

We looked at boolean values in the previous article. PHP has truthy booleans, which are values that are not true or false, but when evaluated inside an expression, they can act like they are.

If we passed 1 to the if statement, PHP would interpret the number 1 as truthy and would execute the statement inside the body.

There are other values that are considered truthy and falsy.

Even if we passed the string “false” to the if statement, it’s still considered truthy.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners