settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Reversed Chars - PHP Task

+5 votes

Write a program that takes 3 lines of characters and prints them in reversed order with a space between them.

Examples:

reversed chars php task

asked in PHP category by user hues

3 Answers

+3 votes
 
Best answer

Mine is with strrev string function (line #8):

<?php

$chars = '';
for ($i = 0; $i < 3; $i++) {
    $chars .= readline()." ";
}

echo strrev($chars);
answered by user Jolie Ann
selected by user golearnweb
0 votes

My solution:

<?php

$input1 = readline();
$input2 = readline();
$input3 = readline();

echo "$input3 $input2 $input1";
answered by user andrew
+2 votes

Mine:

<?php

$chars = '';
for ($i = 0; $i < 3; $i++) {
    $chars .= readline();
}

$output = '';
for ($i = 2; $i >= 0; $i--) {
    $output .= $chars[$i] . " ";
}

echo $output;
answered by user icabe
...