Example 1 — Format a Date String
Zero-pad numbers from an array.
<?php
$parts = [2026, 11, 11];
$date = vsprintf("%04d-%02d-%02d", $parts);
echo $date, PHP_EOL; How It Works
- Prepare the array. It holds year, month, and day.
- Write the format.
%04dpads to four digits with zeros. - Format. vsprintf() returns the new string.
- Print. You see
2026-11-11.

