function test($x) { $c = strlen($x); $i = 1; while ($i <= strlen($x)) { $c--; $z = $z.$x[$c]; $i++; } return $z; } echo test(123);