I have a multi-dimensional array:
membership = array(5) {
[0]=> array(4) { [0]=> string(21) "Group A" [1]=> string(9) "10/1/2011" [2]=> string(9) "3/31/2012" [3]=> string(8) "00004130" }
[1]=> array(4) { [0]=> string(22) "Group B" [1]=> string(8) "4/1/2011" [2]=> string(9) "9/30/2011" [3]=> string(8) "00005005" }
[2]=> array(4) { [0]=> string(22) "Group A" [1]=> string(9) "10/1/2010" [2]=> string(9) "3/31/2011" [3]=> string(8) "00004130" }
[3]=> array(4) { [0]=> string(22) "Group B" [1]=> string(8) "4/1/2010" [2]=> string(9) "9/30/2010" [3]=> string(8) "00005005" }
[4]=> array(4) { [0]=> string(22) "Group B" [1]=> string(8) "10/1/2010" [2]=> string(9) "3/31/2011" [3]=> string(8) "00005005" }
}
I need to discover which group is in the membership array and how many times it appears.
PHP’s count() does not have recursive capability, but it’s output would be ideal if it did (i.e. [‘Group A’] => 2 [‘Group B’] => 3 ).
I thought about using the array_diff_uassoc() but, I’m just not sure. So I thought it wise to ask for some help before I wander aimlessly down the wrong path. I am sure there is more than one way, but I always find very interesting coding concepts on SO.
I’m running php 5.3.5 Thank you in advance for your suggestions and help.
This should do the trick with minimal code:
Sorry for the late post BTW, I wanted to test it and make sure it would work as expected.
Output is: