I have 2 arrays in PHP that look something like this:
$rows = array(11,12,14,14,11,13,12,11);
$cols = array(1,2,1,2,2,2,1,1);
I need to combine these arrays in a way that tells how many of each $cols value is in each $rows value.
So my result should look something like this:
Array
(
[0] => Array
(
[row] => 11
[1] => 2 //the count of 1 cols for 11
[2] => 1 //the count of 2 cols for 11
)
[1] => Array
(
[row] => 12
[1] => 1
[2] => 1
)
...
)
The values of $rows and $cols will change based upon the users input, they may even be strings.
Clarification:
The duplicates values come from the data. Think survey results or test questions. So question 11 had 2 people answer 1 and 1 person answer 2.
Question:
How do I count the number of occurrences of $cols in $rows and add the results into a multidimensional array?
I figured it out. It was not as complicated as I first thought. Just needed a function to calculate the sum. Perhaps it could be more efficient, I would love any ideas on that, but here it is:
The result is: