php - Counting distinct values in a multidimensional array -


i have array looks 1 below. i'm trying group , count them, haven't been able work.

the original $result array looks this:

array (     [sku] => array         (             [0] => 344             [1] => 344             [2] => 164         )      [cpk] => array         (             [0] => d456             [1] => d456         ) ) 

i'm trying take , create new array:

$item[sku][344] = 2; $item[sku][164] = 1; $item[cpk][d456] = 1; 

i've gone through various iterations of in_array statements inside loops, still haven't been able working. can help?

i wouldn't use in_array() here.

this loops through creating array goes.

it seems work without needing first set index 0.

$newarray = array();  foreach($result $key => $group) {        foreach($group $member) {         $newarray[$key][$member]++;     }     } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -