Hello all, i have a function that calcs what's the most repeated value in a string, that string has multiple values including separator chars, the problem is that the function doesn't work for values bigger then 9.
The function "see's" 9 as one char and the value 10 is seen as 2 chars.
Any idea how to fix this?PHP Code:
function mode_of_values($mystring){
$bigger=-1;
$data = $mystring;
$result = count_chars($data, 0);
for ($i=0; $i < count($result); $i++)
if ((chr($i)!=",") and (chr($i)!=";")){
if ($result[$i] != 0)
if($bigger<$result[$i]){
$bigger=$result[$i];
$character=chr($i);
}
}
}
return $bigger.",".$character;
}
mode_of_values("1,3,4;2,3,4;2,5,6;2,6,8");//this works just fine but not when i call like:
mode_of_values("10,11,12;10,13,14;11,12,13");
![]()
Thanks




and rating it.
Reply With Quote