Write a PHP program to create a new string taking the first character from a given string and the last character from another given string
- برمجة بي اتش بي
- 2021-09-08
- mhanasmh00489829403
الأجوبة
<?php
function test($s1, $s2)
{
$lastChars = "";
if (strlen($s1) > 0)
{
$lastChars = $lastChars.substr($s1, 0, 1);
}
else
{
$lastChars = $lastChars."#";
}
if (strlen($s2) > 0)
{
$lastChars = $lastChars.substr($s2, strlen($s2) - 1);
}
else
{
$lastChars = $lastChars."#";
}
return $lastChars;
}
echo test("Hello", "Hi")."\n";
echo test("Python", "PHP")."\n";
echo test("JS", "JS")."\n";
echo test("Csharp", "")."\n";
Sample Output:
Hi PP JS C#
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال