This is the code I have so far. I just started learning PHP today and I'm not sure why my code isn't working.
<?php
function backwards($input)
{
$str = $input;
$revStr = "";
$str = explode(",",$str);
for($x = 0; $x < strlen($str); $x++){
$revStr .= strrev($str[$x]);
}
return $revStr;
}
Any help would be greatly appreciated!
edit: Here is an example input
Php,Arrays,Mysql
here is what i would like the output to be:
phP,syarrA,lqsyM
edit2:
Figured it out. Made a few minor edits. Not sure if it's the most efficient code but it works.
<?php
function backwards($input)
{
$str = $input;
$revStr = "";
$str = explode(",",$str);
for($x = 0; $x < count($str); $x++){
if($x == count($str) - 1){
$revStr .= strrev($str[$x]);
}
else{
$revStr .= strrev($str[$x]) . ",";
}
}
return $revStr;
}