Javascript Php计算字符串中字符的唯一性和发生率

Javascript Php计算字符串中字符的唯一性和发生率,javascript,php,Javascript,Php,我之前写过使用javascript为客户端计算 这是我的职责 var check = {}, string = inputString, count = 0; var occurrence; $.each(string.split(''), function(){ if(!check[this]){ count++; check[this]=true; }) 上面的函数我使用它来计算字符串中出现的数字 比如说 number 1234 will retur

我之前写过使用javascript为客户端计算

这是我的职责

var check = {}, string = inputString, count = 0;
var occurrence;
$.each(string.split(''), function(){
    if(!check[this]){
        count++;
        check[this]=true;
})
上面的函数我使用它来计算字符串中出现的数字

比如说

number 1234 will return 4, as there are number 1,2,3 and 4
number 1233 will return 3, as the unique number are 1,2 and 3
number 1212 will return 2, as the unique number are 1 and 2
我想知道如何将上面的函数转换为返回相同计数的工作php函数

下一件事是我写了另一张支票,它是Getmostocurrence

例如,目的是

number 1212, will return 2, as 1 appear 2 times, and 2 appear 2 times
但是如果数字

1112, the result will be 3, as 1 appear 3 times
如何在php中执行此计数函数

谢谢你的帮助

使用

<?php
$data = "Two Ts and one F.";

foreach (count_chars($data, 1) as $i => $val) {
   echo "There were $val instance(s) of \"" , chr($i) , "\" in the string.\n";
}
?> 
统计字符串中每个字节值(0..255)的出现次数,并以各种方式返回

示例直接取自

<?php
$data = "Two Ts and one F.";

foreach (count_chars($data, 1) as $i => $val) {
   echo "There were $val instance(s) of \"" , chr($i) , "\" in the string.\n";
}
?> 


你也可以很容易地使用它来实现你的第二个目的。

我使用了count char,他们告诉我字符串中有1个“A”的实例。字符串中有1个“a”实例。字符串中有2个“r”实例。字符串中有1个“y”实例。1234年