Converting some values to boolean is a common task while building applications. Let’s say Yes/No or On/Off.

Now, if you want to convert any of these pairs to a boolean, you might end up using conditionals.

Here are all the values that filter_var can effectively convert to their boolean counterpart. value boolean ‘on’ bool(true) ‘On’ bool(true) bool(true) ‘off’ bool(false) ‘Off’ bool(false) bool(false) ‘yes’ bool(true) ‘Yes’ bool(true) bool(true) ‘no’ bool(false) ‘No’ bool(false) bool(false) bool(false) 1 bool(true) ‘0’ bool(false) ‘1’ bool(true) ‘true’ bool(true) ‘True’ bool(true) bool(true) ‘false’ bool(false) ‘False’ bool(false) bool(false) true bool(true) false bool(false) ‘foo’ ‘bar’ NULL
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