In PHP, what are some efficient ways to manipulate and format strings, such as padding with zeros?

When working with strings in PHP, one common task is to manipulate and format them in a specific way. One common manipulation is padding a string with zeros to a certain length. This can be achieved using the str_pad() function in PHP, which allows you to specify the length of the resulting string and the character to pad with.

// Padding a string with zeros to a length of 10
$string = "123";
$paddedString = str_pad($string, 10, "0", STR_PAD_LEFT);
echo $paddedString; // Outputs "0000000123"