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

  • برمجة بي اتش بي

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
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...