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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners