Topic on Extension talk:Arrays

Counting the number of occurences of a value in an array?

4
82.161.136.28 (talkcontribs)

I am looking for a solution to count the number of occurrences of a string in an array. PHP has "array_count_values", did anyone make this available already for Arrays in MW?

[Apple, Pear, Apple, Banana] Apple = 2, Banana = 1, Pear = 1.

Thanks,

Best wishes,

Timo

Dinoguy1000 (talkcontribs)
82.161.136.28 (talkcontribs)

I've added floor to get rid of the decimals.

This works for strings indeed, my problem is counting occurrences of a string in an array of strings. When I copy those into 1 string to let {{count}} work, the string has gotten to long.

Your idea may help me though, I have to implement something to loop through the array counting for each element of the array.

Thanks!

Danwe (talkcontribs)

Simply use arraysearcharray in combination with arraysize.

Reply to "Counting the number of occurences of a value in an array?"