hunterstudio.biz
- 1026 -

Manipulating arrays with callback functions and Collections

In addition to the previous point, to handle arrays and their elements in PHP (php company), 2 other concepts are interesting. I do not (yet) master them enough to go into too much detail.

The array_map, array_filter or array_reduce functions allow you to process arrays by applying callback functions. We can therefore do without for or foreach while processing all the elements of the array

Collections are third-party libraries, for example very popular in Laravel, which will allow you to manipulate arrays in object logic to have something more readable and pleasant than the functions above:

2 examples in English (the other good practices in this article are also very interesting)
A tutorial in French
The "collect" bookstore on Github
Similar things can be found in other PHP frameworks as well.

Personally, I am always attracted by these programming challenges, it is a good opportunity to rub shoulders with algorithmic complexities, and therefore to dig into the language + in depth, to discuss with other developers on the solutions found, to discover practices, tips, etc. It really allows you to progress as a developer. 2021 is just beginning, I wish you all a very happy new year, rich in code, and good programming practices!

Web

  1. 21 Fév. 2021The intersection of several arrays5805
  2. 9 Janv. 2021Keep up to date with the latest Php releases995