array_filter() is Your Friend


Simple, easy and useful. Have a form where a list has been created client-side? Fear they might leave part of that list blank? Turning that list into an array to save? If you’ve answered yes to those questions, then there are probably 2 of you that this will help. For those of you still saying yes, array_filter is pretty amazing.

With an $entry and a ‘callback’ you too can use array_filter() in no time.

// Your array
$ray_lewis = ('Ravens', 'linebacker', 'may have stabbed someone', '');

// notice the blank piece there? Unacceptable!
$defense_attorney = array_filter($ray_lewis);

// do what you want with your array with no blanks
// more deets on

Short. Simple. Like my brain… and my attention…um… bridge? potato?

Notify of
Inline Feedbacks
View all comments

John Hartley is a Director of Product Engineering at Beam Dental in Columbus, OH. With 5+ years of leadership experience he has worked in startups, agencies, and began his career as a freelance Front End Developer. Always looking to iterate, this blog is a place for him to share his knowledge as well as hone his craft, challenge assumptions, and build a strong base of leadership and management knowledge. Connect with him on LinkedIn

Would love your thoughts, please comment.x