For loop only works first time through

This is my problematic function:
[php]function LikeCounter($names)
{
$likes = 0;
echo($names);
for ($i = 0; $i == $count; $i++)
{
echo(‘Works!’);
if ($names{$i} == ‘,’)
{
$likes += 1;
}
}
return $likes;
}[/php]

This function is used to count the commas in the string in order to determine how many users “liked” the comment.

When I register a new user and go to his profile, there is already a message on the profile page and the message “Works!” is shown along with 0 “likes”.

When I “like” the comment, "username, " is echoed, but not “Works!” and the returned value is still 0

If I keep “liking” the comment, I just end up with “username, username, username, …” echoed and the same problem occurs.

Why is the loop only working the first time I call the function?

Thanks in advance! :slight_smile:

I forgot to add that $count is the length of $names

[php]
function LikeCounter($names)
{
$likes = 0;
$count = strlen($names);
echo($names);
for ($i = 0; $i == $count; $i++)
{
echo(‘Works!’);
if ($names{$i} == ‘,’)
{
$likes += 1;
}
}
return $likes;
}
[/php]

Duplicate topic. You marked the other one as solved as such I am locking this one.

Sponsor our Newsletter | Privacy Policy | Terms of Service