Write a PHP program to create a new string made of every other character starting with the first from a given string.
<?php function test($s) { $result = ""; for ($i = 0; $i < strlen($s); $i++) { if ($i % 2 == 0) $result = $result.substr($s,$i,1); } return $result; } echo test("Python")."\n"; echo test("PHP")."\n"; echo test("JS")."\n";
Sample Output:
Pto PP J
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output: