计算数组中的重复数量?

Jus*_*n k 1 php arrays

我有一个数组联系下面的话

(“hello”, “apple”, “hello”, “hello”, “apple”, “orange”, “cake”)
Run Code Online (Sandbox Code Playgroud)

Result here should be 5

你能否告诉我是否有一个库函数PHP,我可以用来计算我的数组中有多少重复的单词?任何帮助将不胜感激.

Jas*_*ary 5

您可以结合array_unique()使用count():

$number_of_duplicates = count($words) - count(array_unique($words));
Run Code Online (Sandbox Code Playgroud)

注意: PHP有超过一百个数组函数.学习它们将使您成为更好的PHP开发人员.