T
T
toaster_users2014-06-02 07:40:04
PHP
toaster_users, 2014-06-02 07:40:04

How to find duplicate pairs of numbers in n php arrays?

Hello, can you please tell me how to find duplicate pairs of numbers in n arrays?
there are n arrays of the form:

$array_1 = array (1,2,3,4,5,8,9);
$array_2 = array (1,3,6,4,5,7,9);
....
$array_n = array (6,2,3,7,5,11,10);

It is necessary to find how many times pairs of numbers are repeated.
Let's say for the given example of three arrays.
The answer should be of the form: 1 and 2 - occurs 1 time; 2 and 3 - occurs 2 times ... etc. for all numbers.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mikhail Osher, 2014-06-02
@miraage

Dig towards array_count_values.

M
Mikhail Alekseev, 2014-06-02
@Fandorin

You can use a hash, loop through the first array, take i and i + 1 numbers,
create a key for the hash "1-2" from it, check if there is a value in the hash with such a key, if not, then create and assign the value 0 , otherwise add 1. Further with other arrays similarly, using a single hash. At the end, print the contents of the hash.

T
toster_users, 2014-06-02
@toster_users

thanks to all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question