How can I include leading zeros in a PHP for loop iteration?

When iterating over numbers in a PHP for loop, you can include leading zeros by using the str_pad function to format the number with the desired number of digits. This function will add zeros to the left of the number if it is shorter than the specified length.

for ($i = 1; $i <= 10; $i++) {
    $padded_number = str_pad($i, 2, '0', STR_PAD_LEFT);
    echo $padded_number . "\n";
}