HomePHP Validating Boolean Values and Float Numbers with Filters in PHP 5
Validating Boolean Values and Float Numbers with Filters in PHP 5
Welcome to the fourth part of a series covering the use of filters in PHP. In this article, you'll learn some very useful ways to take advantage of the capabilities of the filter extension to validate Boolean values in arrays; we'll also show you how to validate float numbers.
If you ever thought that PHP 5 comes mostly from its object model, then fortunately I have to say that you're wrong. The latest version of PHP comes packaged with many other handy features that have contributed enormously to making it the mature language that it is nowadays.
However, along with its popular improvements, PHP provides a powerful set of filters for performing all sorts of clever validation on variables. These filters can check integers and float numbers, email addresses and URLs, Boolean values and IPs and much, much more.
This group of filters, also commonly known as "filter extensions," allow you to check for incoming data by using an extremely friendly approach. So if you're searching for a solid library that lets you perform strict validation on user-supplied parameters before doing something useful with them (like inserting them into a database table, for instance), then hopefully this series of articles might be what you need. In it, you'll find a concise guide that will show you how to work with the most useful filters that come bundled with this extension.
And now that you know what to expect from these tutorials, it's time to quickly review the concepts that were covered in the last one. In that specific installment of the series, I discussed the usage of the FILTER_VALIDATE_BOOLEAN filter. As its name suggests, it was used for checking Boolean values in conjunction with the already familiar "filter_var()" function.
In addition, it's fair to note that the aforementioned filter was utilized for determining whether or not the value assigned to a single variable was Boolean. As you learned in previous parts of the series, the filter extension permits you to validate elements of a given array very easily as well. Therefore, in this fourth chapter I'm going to explain how to check for Boolean values in arrays, as well as how to validate float numbers using another handy filter.
Are you ready to continue exploring the numerous capabilities provided by the PHP 5 filter extension? Then, let's jump in!