This may not be the best way, but its all I've got at 3am 😃
<?
//Question: count how many 6's are in the string 163462?
$string = '163462';
$wanted_num = 6;
for ($i=0;$i<strlen($string);$i++)
{
if ($string{$i} == $wanted_num)
{
$count_num++;
}
}
echo "Number of occurances of ".$wanted_num." in ".$string.": ".$count_num;
?>
Note that the $string value (ie 163462 in this case) MUST be surrounded by quotes, otherwise it doesn't work, kinda odd for a number but kept be guessing for a few minutes.