Write a PHP program to create a new string of the characters at indexes 0,1,4,5,8,9 ... from a given string
<?php function test($s) { $result = ""; for ($i = 0; $i < strlen($s); $i=$i+4) { $c = $i + 2; $n = 0; $z = $c > strlen($s) ? 1 : 2; $n = $n + $z; $result = $result.substr($s, $i, $n); } return $result; } echo (test("Python"))."\n"; echo (test("JavaScript"))."\n"; echo (test("HTML"))."\n";
Sample Output:
Pyon JaScpt HT
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:
need an explanation for this answer? contact us directly to get an explanation for this answer