w3resource

PHP Exercises: Create a new string using two given strings s1, s2, the format of the new string will be s1s2s2s1

PHP Basic Algorithm: Exercise-59 with Solution

Write a PHP program to create a new string using two given strings s1, s2, the format of the new string will be s1s2s2s1.

Sample Solution:

PHP Code :

<?php
// Define a function named 'test' that concatenates two strings in a specific order
function test($s1, $s2)
{
    // Concatenate the strings in the order: s1 + s2 + s2 + s1
    return $s1 . $s2 . $s2 . $s1;
}

// Test the 'test' function with different input strings and display the results
echo test("Hi", "Hello")."\n";
echo test("whats", "app");
?>

Sample Output:

HiHelloHelloHi
whatsappappwhats

Flowchart:

Flowchart: Create a new string using two given strings s1, s2, the format of the new string will be s1s2s2s1.

PHP Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a PHP program to check three given integers (small, medium and large) and return true if the difference between small and medium and the difference between medium and large is same.
Next: Write a PHP program to insert a given string into middle of the another given string of length 4.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.