Q:

Write a PHP program to create a string like "aababcabcd" from a given string "abcd"

0

Write a PHP program to create a string like "aababcabcd" from a given string "abcd"

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
function test($s)
{
  $result = "";
            for ($i = 0; $i < strlen($s); $i++)
            {
                $result = $result.substr($s, 0, $i + 1);
            }
            return $result;
 }

echo test("abcd")."\n";
echo test("abc")."\n";
echo test("a")."\n";

Sample Output:

aababcabcd
aababc
a

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now