Write a PHP program to check if a given string begins with 'abc' or 'xyz'. If the string begins with 'abc' or 'xyz' return 'abc' or 'xyz' otherwise return the empty string
<?php function test($s1) { if (substr($s1,0,3) == "abc") { return "abc"; } else if (substr($s1,0,3) == "xyz") { return "xyz"; } else { return ""; } } echo test("abc")."\n"; echo test("abcdef")."\n"; echo test("C")."\n"; echo test("xyz")."\n"; echo test("xyzsder")."\n";
Sample Output:
abc abc xyz xyz
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