Write a PHP program to create a new string using 3 copies of the first 2 characters of a given string. If the length of the given string is less than 2 use the whole string
- برمجة بي اتش بي
- 2021-09-08
- mhanasmh00489829403
الأجوبة
<?php
function test($s1)
{
$extra_Front = "";
if (strlen($s1) < 2)
{
return $s1 . $s1 . $s1;
}
else
{
$extra_Front = substr($s1, 0, 2);
return $extra_Front . $extra_Front . $extra_Front;
}
}
echo test("abc") . "\n";
echo test("Python") . "\n";
echo test("J") . "\n";
Sample Output:
ababab PyPyPy JJJ
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال