Q:

Write a PHP program to concat two given strings (lowercase). If there are any double character in new string then omit one character

0

Write a PHP program to concat two given strings (lowercase). If there are any double character in new string then omit one character

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now