'PHP STRING ISSUE IN DISPAYIND DATA
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
Solution 1:[1]
$string = "aba";
echo 'output is :- '.substr_count($string,"a");
$string = "cat";
echo 'output is :- '.substr_count($string,"a");
Hope this can be useful
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Amaan Warsi |