0

here is my associative array, I'm trying to count the occurrences or each of the duplicates here (r-17-VM) (v-2-VM) ignoring "Control domain on host"

Array
(
    [0] => Array
        (
            [0] => r-17-VM
            [1] => r-17-VM
            [2] => r-17-VM
            [3] => r-17-VM
            [4] => r-17-VM
            [5] => r-17-VM
            [6] => r-17-VM
            [7] => r-17-VM
            [8] => r-17-VM
            [9] => r-17-VM
            [10] => r-17-VM
            [11] => r-17-VM
            [12] => r-17-VM
            [13] => v-2-VM
            [14] => v-2-VM
            [15] => v-2-VM
            [16] => v-2-VM
            [17] => v-2-VM
            [18] => v-2-VM
            [19] => v-2-VM
            [20] => v-2-VM
            [21] => v-2-VM
            [22] => v-2-VM
            [23] => v-2-VM
            [24] => v-2-VM
            [25] => v-2-VM
            [26] => Control domain on host
            [27] => Control domain on host
            [28] => Control domain on host
            [29] => Control domain on host
            [30] => Control domain on host
            [31] => Control domain on host
        )

)

Thank you

Deano
  • 11,582
  • 18
  • 69
  • 119
  • 6
    ok, we understand what you want, now we want to understand what you've tried and what kind of problem you have? – Iłya Bursov Apr 09 '15 at 03:23
  • Possible dublicate: http://stackoverflow.com/questions/9599374/count-string-occurrences-in-array – sergio Apr 09 '15 at 03:36

1 Answers1

2

Use array_count_values. It returns an array of the number of times each value is repeated:

$frequency = array_count_values($array);
var_dump($frequency);

For your array this outputs:

array(3) {
  ["r-17-VM"]=>
  int(13)
  ["v-2-VM"]=>
  int(13)
  ["Control domain on host"]=>
  int(6)
}
wavemode
  • 2,076
  • 1
  • 19
  • 24