Suppose there is an N-th number of arrays containing user IDs.

An example of such an array:

Array ( [0] => 241439019 [1] => 326313377 [2] => 289968681 [3] => 144237940 [4] => 174916220 ) 

How to remember people trapped in these arrays?

PS User ID can get into several arrays at once and it should also be remembered.

Expected output:

User: "The identifier", and "The number of times the indicator was repeated in arrays"

  • merge arrays into one using array_merge and count repetitions array_count_values - teran

1 answer 1

User ID can go into several arrays at once.

Suppose you have three arrays with user IDs

 $array_1 = array(241439019, 326313377, 289968681, 144237940, 174916220); $array_2 = array(241439020, 326313378, 289968681, 144237940, 174916220); $array_3 = array(241439019, 326313379, 289968680, 144237940, 174916220); 

Then you can merge the arrays and count the number of duplicate elements in this way:

 $array = array_merge($array_1, $array_2, $array_3); $array = array_count_values($array); array_walk($array, function($all, $id){ echo "$id: $all<br>"; }); 

Result:

 241439019: 2 326313377: 1 289968681: 2 144237940: 3 174916220: 3 241439020: 1 326313378: 1 326313379: 1 289968680: 1 
  • Using this method, can I find out the number of user reps in these arrays? (I need this in order to determine how many times a person has performed a certain action. To display the rating on the main page of the site) - Coffee inTime
  • @CoffeeinTime yes, as a result of the script in the $ id variable will be the user's ID, and in $ all the number of visits. - Edward
  • thank you I will try. - Coffee inTime