Book Review - PHP Array Filtering, The Use cases

Do you use arrays? Do you use the most effective inbuilt functions to filter multiple arrays? If not then this book ( will be incredibly useful for you!

This book is a fantastic resource its almost like a manual for array's covering three core areas

1) Difference

"The difference functions are especially useful when you have more than two arrays to compare. Compared to the PHP code needed to do the same work, they become a very clean solution."

2) Intersection

"Array intersection is the mirror of array difference. With the difference functions you are finding out what is in an array that is not in any other array. With intersections you will find out what is in this array that is also in all the other arrays."

3) Filtering

"The filtering toolkit. Outside of difference and intersection, these functions will accomplish most all of your filtering needs."

Each chapter covers in detail the array functions with explanations on why you would use one of the array functions with practical examples you can use right away, for instance one of the examples:

Split dataset up by odd and even in display logic

You have a dataset that, for purely display reasons, you want to split up into an odd list and an even list. You often have to slice and dice data when displaying it. Code like the following allows you to do that without changing the original data and without having to mix display logic in with your business logic.

$resultList = array(
  'Ted' => 11, 'Nick' => 12,
  'Bob' => 32, 'John' => 7 );
$odd = function($value) { return $value % 2 !== 0;

$even = function($value) {
??  return $value % 2 === 0;

$oddList = array_filter($resultList, $odd); 
$evenList = array_filter($resultList, $even);
echo 'Odd: ', print_r($oddList, 1);
echo 'Even: ', print_r($evenList, 1);


Odd: Array 
  [Ted] => 11
  [John] => 7 
Even: Array 
  [Nick] => 12
  [Bob] => 32 


I would recommend this book to anyone looking for a better understanding of arrays or even to brush up on them, the book is laid out in organised way its very easy to move from examples to example or straight to a particular area of interest.

You can learn more about this book and ways to purchase it at the publishers website Developer.Press

David Carr

David Carr

For the past 12 years, I’ve been developing applications for the web using mostly PHP. I do this for a living and love what I do as every day there is something new and exciting to learn.

In my spare time, the web development community is a big part of my life. Whether managing online programming groups and blogs or attending a conference, I find keeping involved helps me stay up to date. This is also my chance to give back to the community that helped me get started, a place I am proud to be apart of.

Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie, staying in playing games on the sofa or planning a trip to someplace I’ve never been before.