I'm trying to create a function to count the occurrences of a letter within a string. Here is what I have so far:
<?php
function charCount ($str, $char){
for($i=0;$i <= strlen($str);$i++){
if($str[$i] == $char){
echo $char;
}
}
}
?>
<?php
$string = charCount ("This is a test", "t");
echo "$string";
?>
The output should just be a number.