Accessing Digits of a Number in PHP
Attempting to get a character of a number will cause an error:
<?php
$num = 12345;
echo $num[0]; // will cause an error
?>
To solve the problem, you can convert our number to a string:
<?php
$num = 12345;
$str = (string) $num;
echo $str[0]; // will output '1'
?>
Given the number 12345. Find the sum of the digits
of this number.
Given the number 12345. Find the product
of the digits of this number.
Given the number 12345. Rearrange the digits
of this number in reverse order.