How can you efficiently format numbers in PHP to include leading zeros?

When formatting numbers in PHP to include leading zeros, you can use the `str_pad()` function to add zeros to the left of the number. This function takes the input number, desired length, and padding character as parameters. By specifying '0' as the padding character and the desired length of the final number, you can efficiently format numbers to include leading zeros.

$number = 7;
$length = 4;
$formatted_number = str_pad($number, $length, '0', STR_PAD_LEFT);
echo $formatted_number; // Output: 0007