- 6338 -

The intersection of several arrays

In one of the exercises, you had to find the intersection of several arrays, that is, the elements common to several arrays. Easy ! custom php application development offers the array_intersect function which is used for just that! Except that this function takes as parameters the arrays in which to find the intersection.

And what I have on my side is a (big) table that contains all my tables to test. And depending on the dataset, I don't know how many I have, so can't write

This is where the "..." decomposition operator comes in, to decompose my big table into all of these elements

Block and break your while Several times it was necessary to use while during Advent of Code. And while I wasn't a big fan, I use while (true) more and more. But it remains "dangerous" to code because as long as the code is not finalized, each test can lead to an infinite loop ... It is therefore interesting to use a "blocker"

Here, I think there won't be 1,000+ possible iterations, so if I hit 1000, I "break" my while and avoid my infinite loop.

Likewise, with a while true, you will need to use "break" to exit the loop once the stop condition is reached. The stop condition is therefore moved directly in the logic only in the parentheses of the while. In use, I find it more readable.

Once the code for my while is finalized, I can of course remove this blocker.

Functions linked to tables

PHP offers many functions available for manipulating arrays. Here are a few that I used regularly during Advent of Code:

array_unique: Keep only one occurrence of each element of the array (sorting of duplicates)
str_split: Transform a character string into an array
array_intersect: The intersection of the elements of several arrays (the common elements)
array_slice: Split an array and keep only a portion
array_search: Find the key of a specific element in an array
array_count_values: Count the occurrences of each element
array_merge: Merge arrays
XXsort: Sort an array, the Xs are to be replaced according to the type of sort desired

It's hard to know them all ... But it's a good practice, when working with an array in PHP, to ask yourself if there isn't already a function that can do what you want to do.


  1. 4 Août 2022PHP Website Development: How Long Does It Take?100
  2. 8 Juil. 2022PHP Development Team: What Does It Consist Of?371
  3. 27 Juin 2022Working in a web design agency262
  4. 8 Juin 2022PHP Developer Careers: What to Expect400
  5. 15 Mai 2022Is it Profitable to Do a PHP Job and Service in Canada?463
  6. 30 Oct. 2021What is the Enigma of Cladx?2710
  7. 2 Sept. 2021Help Wanted: PHP Development Company is Looking for Skilled Workers1326
  8. 5 Août 2021A Programmer's Guide to PHP687
  9. 14 Mai 2021So what is web development in 2021 ?2332
  10. 14 Avril 2021A perfect means of goal management3382
  11. 9 Fév. 2021Manipulating arrays with callback functions and Collections1465
  12. 9 Janv. 2021Keep up to date with the latest Php releases1452