Is using the Modulo operator a more efficient way to extract the last digit of a number in PHP compared to converting it to a string?

Using the Modulo operator is generally considered a more efficient way to extract the last digit of a number in PHP compared to converting it to a string. This is because the Modulo operator directly calculates the remainder of the division operation, which can be used to isolate the last digit. Converting the number to a string involves more overhead and processing. Therefore, for extracting the last digit of a number, using the Modulo operator is a more efficient approach.

// Using Modulo operator to extract the last digit of a number
$number = 12345;
$lastDigit = $number % 10;
echo "Last digit of $number is: $lastDigit"; // Output: Last digit of 12345 is: 5