How can PHP maintain the leading zeros in a ZEROFILL integer when performing arithmetic operations?

When performing arithmetic operations on a ZEROFILL integer in PHP, the leading zeros are typically lost because PHP treats the ZEROFILL integer as a regular integer. To maintain the leading zeros, you can convert the ZEROFILL integer to a string before performing any arithmetic operations. This way, PHP will treat the value as a string and preserve the leading zeros.

$zerofillInt = '000123';
$number = 5;

// Convert ZEROFILL integer to string before performing arithmetic operations
$result = str_pad((string)((int)$zerofillInt + $number), strlen($zerofillInt), '0', STR_PAD_LEFT);

echo $result; // Output: 000128