<php $num = 1234; $rem =0; $rev =0; $originalnum = $num; while($num > 1) { $rem = $num %10; $rev = ($rev * 10)+ $rem; $num = $num /10; } echo "Original Number: ". $originalnum; echo " Reverse : ". $rev; >The Logic here is simple. First get the given number and extract the final digit. Initially the reverse of the number will be zero, on each iteration multiply the reverse with 10 and add the modulus result.
↧
How to reverse a number in php without built in functions
↧