1. <?php
    2. class Solution {
    3. /**
    4. * 123
    5. * 321
    6. * @param $x
    7. * @return false|float|int
    8. */
    9. public function reverse($x) {
    10. $res = 0;
    11. while ($x != 0) {
    12. $res = floor($res * 10 + $x % 10);
    13. $x = ($x > 0) ? floor($x / 10) : ceil($x / 10);
    14. if ($res > pow(2, 31) - 1 || $res < -pow(2, 31) - 1) {
    15. return 0;
    16. }
    17. }
    18. return $res;
    19. }
    20. }
    21. $cls = new Solution();
    22. $r = $cls->reverse(1230);
    23. print_r($r);