Jump to content

[SOLVED] Help with counting same numbers in a string.


Adam1239

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.