To reverse a number in PHP without using built-in function declare a variable to store the reversed number, and initially assign zero to it. Now, extract the last digit from the original number, and multiply the reverse number with 10, then add the extracted digit to reversed number, and divide the original number by 10.
Also, read this How to earn money online
A number can be written in reverse order.
For example
12345 = 54321
<?php
$num = 12345;
$forThisNumber = $num;
$rev = 0;
while($num > 0)
{
$a = $num % 10; // 1st time = 5
$rev = ($rev * 10) + $a; // 1st time (0 * 10 = 0 + 5 = 13)
$num = (int)($num / 10); // 1st time remained = 1234
}
echo "original number is = <b> $forThisNumber </b> <br/> Reverse of number is = <b> $rev </b>";
?>
You can reverse number using PHP built-in function
$num = 1234567;
$rev = strrev($num);
echo "original number is = <b> $num </b> <br/> Reverse of number is = <b> $rev </b>";
sum of digits in php
<?php
$num = 12345;
$forThisNumber = $num;
$sum = 0;
while($num > 0)
{
$a = $num % 10; // 1st time = 5
$sum = $sum + $a; //1st time 0 + 5 = 5
$num = (int)($num / 10); // 1st time remained 1234
}
echo "original number is <b>$forThisNumber </b> <br/> sum of number is = <b> $sum </b>";
?>