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

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