|
-
May 28th, 2005, 01:58 AM
#1
Thread Starter
Fanatic Member
Bug in function [Resolved]
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.
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");
Any idea how to fix this?
Thanks
Last edited by TDQWERTY; May 28th, 2005 at 03:45 PM.
-
May 28th, 2005, 05:01 AM
#2
Fanatic Member
Re: Bug in function
1,3,4;2,3,4;2,5,6;2,6,8
I don't think that's a string. String literal is like "1,3,4;2,3,4;2,5,6;2,6,8" quoted with double quotes or '1,3,4;2,3,4;2,5,6;2,6,8' with single quotes. Your function seems to have arguments
function some_function(arg0,arg1,arg2,arg3...) which signature is undefined.
-
May 28th, 2005, 06:25 AM
#3
Lively Member
Re: Bug in function
dude,
you have used the function in a wrong way see the parameter for count-chars is a string it does not matter whether it is 11 or 111.
you need to write your own function that will do so.
-amresh-
Jobs: "Do u want to sell colored sugar water or change the world?"
Get Firefox Now!!!
Mendhak leaving town. 
-
May 28th, 2005, 07:14 AM
#4
Thread Starter
Fanatic Member
Re: Bug in function
 Originally Posted by nebulom
1,3,4;2,3,4;2,5,6;2,6,8
I don't think that's a string. String literal is like "1,3,4;2,3,4;2,5,6;2,6,8" quoted with double quotes or '1,3,4;2,3,4;2,5,6;2,6,8' with single quotes. Your function seems to have arguments
function some_function(arg0,arg1,arg2,arg3...) which signature is undefined.
Yes, i missed something there, i should have said:
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");
I tryed already to fix that function but never got it to work
-
May 28th, 2005, 03:45 PM
#5
Thread Starter
Fanatic Member
-
May 29th, 2005, 08:01 PM
#6
Fanatic Member
Re: Bug in function
 Originally Posted by TDQWERTY
Solved!
Mind posting how?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|