Formatting numbers with leading zeros in PHP
Hi everyone! I'm new to PHP and ran into what seems like a simple task, but I can't find the right solution.\n\nI need to display order IDs in a format where the number always takes up, say, 5 digits. If the ID is 1, it should display as "00001". If the ID is 123, then as "00123". That is, zeros are added on the left to the required length.\n\nI tried using simple string concatenation, for example: `$order_id = '00000' . $id;`, but this doesn't work when the number already has multiple digits. It results in "00000123", but I need "00123".\n\nI tried looking in the documentation, but there are many functions and I got confused. Here's an example of my code that doesn't produce the desired result:\n\n```php\n\n```
No answers yet.
Log in to leave an answer