When you’re working with a collection in PHP, most notably, arrays in PHP, there are two ways in which you primarily see the information manipulated:
- through
for
loops, - through a variety of the
array
functions that PHP provides.
For what it’s worth, I think the array
functions provide greater readability but they have been shown to be slower (especially with larger data – with smaller data, it’s naturally going to be negligible).
I often work with for
loops and related functions to achieve the same thing but I thought it might be worth look at an example from the previous post and how I used the array
functions to achieve the same things as a for
loop.
Ultimately, this is is a comparison post but I think it’s good to see how the same code can be written in different ways.