Write a PHP program to count the string "aa" in a given string and assume "aaa" contains two "aa".
<?php function test($s) { $ctr_aa = 0; for ($i = 0; $i < (strlen($s) - 1); $i++) { if (substr($s, $i, 2) == "aa") { $ctr_aa++; } } return $ctr_aa; } echo test("bbaaccaag")."\n"; echo test("jjkiaaasew")."\n"; echo test("JSaaakoiaa")."\n";
Sample Output:
2 2 3
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer