Online Snippets Library

Reverse number in php without built in functions

In Below example we will reverse number without built in functions.

Example

<?php
$num = 2019;
$reversenum = 0;
while ($num != 0)
{
$reversenum = $reversenum * 10 + $num % 10;
$num = (int)($num / 10); 
}
 
echo "Reverse number: $reversenum";
?>

Out Put

Reverse number: 9102