1
<?php

$revs=0;
$no=123;
while($no!=0)
{
$revs = $revs*10;
$revs = $revs +( $revs%10);
$no = ($no/10);
}
echo revs;

?>

The code written above doesn't work it shows following error

"Notice: Use of undefined constant revs - assumed 'revs' in /opt/lampp/htdocs/testprojct/proj.php on line 26

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Machine
  • 103
  • 7
  • 1
    Besides your syntax error you have 2 little logical errors: 1) `($revs%10)` must be `($no%10)`, since you want the last digit from your number and not from the reversed one 2) `$no = ($no/10);` You must cast the result to an int, so your loop actually stops, e.g. `$no = (int)($no/10);` – Rizier123 Feb 26 '16 at 13:07
  • You just missed `$` sign when you are `echo`ing.. change `echo revs;` to `echo $revs;` – phpfresher Feb 26 '16 at 13:09
  • `echo implode('', array_reverse(str_split($no)));` – Mihai Matei Feb 26 '16 at 13:13

1 Answers1

2

You just forgot the $ in front of revs where you echo it.

Vasil Rashkov
  • 1,818
  • 15
  • 27