Q:

Write a PHP program to concat two given strings. If the given strings have different length remove the characters from the longer string

0

Write a PHP program to concat two given strings. If the given strings have different length remove the characters from the longer string

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) < strlen($s2))
       {
          return $s1 . substr($s2, strlen($s2) - strlen($s1));
       }
     else if (strlen($s1) > strlen($s2))
       {
           return  substr($s1, strlen($s1) - strlen($s2)) . $s2;
       }
     else
       {
          return $s1 . $s2;
       }
 }

echo test("abc", "abcd") . "\n";
echo test("Python", "Python") . "\n";
echo test("JS", "Python") . "\n";

Sample Output:

abcbcd
PythonPython
JSon

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