[SOLVED] PHP STRING ISSUE IN DISPAYIND DATA

Issue

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:

  1. Ask the candidate to assign str1=cat. Output should 1

  2. Ask the candidate to type : mno. Output should be 0

  3. Ask the candidate to type : aaabbbccc. Output should be 3

Solution

$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");

Answered By – Naveen Chaudhari

Answer Checked By – Willingham (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *