Jump to content

Recommended Posts

Hi, I am quite new to php and i'm looking for a little help with counting how meny times the same number as come up in a string.

 

example: I'm useing a mysql database and the row i want to count reads "2-3-2-2-6".

So if i had something that could count how meny times the same number as come up in that row, it would return 3 because the 2 as come up 3 times. there as got to be an easyer way to archive this, other than doing it this way:

 

$p = explode("-",$fetch[$row]);

if($p[0] == "2" && $p[2] == "2" && $p[3] == "2"){ etc ...

 

i have been looking all over for a solution but just cant seem to find one. so if you could point me in the right direction it would help alot.

 

Thank you,

Adam.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.