Write a program for the below mentioned question:
Create a string variable, str1 and assign it some value, say “abcd”
Find the number of times the letter ‘a’ occurs in str1 and print the count to console.
For example, if str1 = aba, the output should be 2
Note : You can take syntax help from w3schools.com
Tests:
Ask the candidate to assign str1=cat. Output should 1
Ask the candidate to type : mno. Output should be 0
Ask the candidate to type : aaabbbccc. Output should be 3
CodePudding user response:
$string = "aba"; echo 'output is :- '.substr_count($string,"a");
$string = "cat"; echo 'output is :- '.substr_count($string,"a");
Hope this can be useful
CodePudding user response:
$string = "cat"; echo 'output is :- '.substr_count($string,"a");
$string = "mno"; echo 'output is :- '.substr_count($string,"a");
$string = "aaabbbccc"; echo 'output is :- '.substr_count($string,"a");