Write a PHP program to concat two given strings (lowercase). If there are any double character in new string then omit one character
<?php function test($s1, $s2) { if (strlen($s1) < 1) { return $s2; } if (strlen($s2) < 1) { return s1; } return substr($s1, strlen($s1)-1, 1) <> substr($s2, 0, 1) ? $s1 . $s2 : $s1 . substr($s2, 1, strlen($s1)-1); } echo test("abc", "cat")."\n"; echo test("Python", "PHP")."\n"; echo test("php", "php")."\n";
Sample Output:
abcat PythonPHP phphp
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