List array duplicates with count

后端 未结 7 2006
孤街浪徒
孤街浪徒 2020-11-30 09:06

I have an array which contains the following results

red 
red
red
blue
blue
Green
White
Grey

and I want to get duplicate count of every val

7条回答
  •  独厮守ぢ
    2020-11-30 09:41

    make another array of counts ....and loop on the original array putting a condition that if it found red increment the 1st cell of the count array ...if it found blue increment the second cell in the count array ....etc. Good Luck .

提交回复
热议问题