What is the correct way to access and display individual numbers from a variable in PHP?

To access and display individual numbers from a variable in PHP, you can convert the variable to a string and then use array access to get each digit. You can then loop through the string and display each digit separately.

$num = 12345;
$numStr = (string) $num;

for ($i = 0; $i < strlen($numStr); $i++) {
    echo $numStr[$i] . "<br>";
}