In PHP, how can leading zeros be added to numbers below a certain threshold within an array?

When dealing with numbers in an array in PHP, if you want to add leading zeros to numbers below a certain threshold, you can achieve this by iterating through the array and using the str_pad() function to add leading zeros to the numbers that meet the condition.

<?php
// Array of numbers
$numbers = [5, 15, 3, 25, 8];
$threshold = 10;

// Iterate through the array and add leading zeros to numbers below the threshold
foreach ($numbers as $key => $number) {
    if ($number < $threshold) {
        $numbers[$key] = str_pad($number, 2, '0', STR_PAD_LEFT);
    }
}

// Output the modified array
print_r($numbers);
?>