What is the function in PHP to pad a number with zeros at the beginning?

To pad a number with zeros at the beginning in PHP, you can use the str_pad() function. This function allows you to specify the length of the resulting string, the padding character (in this case, zero), and whether to pad from the left or right.

$num = 123;
$padded_num = str_pad($num, 5, "0", STR_PAD_LEFT);
echo $padded_num; // Output: 00123