Why don’t I use array iterators in PHP?
Art VS Performance
When I started learning PHP, most beautiful thing which I could do is to use array_walk, array_map and array_filter functions along with some closure which will attracts some cheers. Today I told my team that they should remove it. But why? The question was raised instantaneously. I said, do the benchmark and you will know the answer.
PHP Functions are overkill! Which should be the part of third party libraries are part of core libraries. Unfortunately, our interview selections make us learn the unwanted core functions. Two years experience favorite question would be different between them! Give it another year and you would know why for loops are great!
Arguably – Performance isn’t much! Check few results over here but then it also depends on how much traffic are you handling. This demands a read on an article on Freaks – Sanity in Insanity I wrote. The overall results from above read is as following:
//1M numbers across a dozen attempts Foreach: 0.7 sec Map on closure: 3.4 sec Map on function name: 1.2 sec.
But then – Readability!
The functions – array_walk, array_map and array_filter kill the readability all together. It might reduce the number of lines you are reading but – and it is a big but – the loops are more familiar as well as keeps thing in indentation.