Reverse number program in PHP using for loop

Last updated:6th Jul 2022

In this program, you will find the reverse of the number by using for loop.

<?php
$n=1345;
$copy=$n;
$rev=0;
for(;$n>0;$n=(int)($n/10))
{
    /*It will find the reverse of the number.*/
    $rev=$rev*10+$n%10;
}
echo "reverse of number $copy is:$rev";
?>

output

reverse of number 1345 is:5431

Related Program