Write a PHP program to concat two given strings. If the given strings have different length remove the characters from the longer string
<?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
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