Fred’s post last week was about filtering through arrays of posts and ordering them. He foreached through arrays, and then used PHP’s usort() function to get a list of alphabetized posts with comments open. That got me thinking a little bit about a topic I very briefly touched on in my summary of the JavaScript ecosystem: functional programming. Functional programming is one of the most interesting and valuable things I’ve started to understand in the last few years. I think functional programming is one of the most interesting and valuable things I’ve started to understand in the last few years. It’s not for everyone though, and it’s not always that relevant to working with WordPress. But it actually shines when doing things like processing and sorting arrays in PHP (again, as Fred’s article offered a way of doing) in a more compact and fluent way. So my hope it to explain some more of the theory of this weird “buzzword” while also giving you concrete and practical uses that you may put it to. A Quick Summary of Programming Paradigms foreach is Procedural Filtering an array with foreach is very “procedural.” That is: we’re describing to the PHP interpreter exactly each step it should
Share This