Today, we will learn how to reverse a number in PHP.
First consider the number 1234. Here we need to get last number first. Hence i am using the modulus operator with divisor value as 10 for getting the remainder value to move from last into first place. Shall we go through the program to reverse a number in PHP now?
Program: Reverse a Number in PHP
$m = 1234; $r=0;
for($i=0; $i<3; $i++)
$m = $m/10;