How format number value in php?

You should use str_pad : https://www.php.net/manual/en/function.str-pad.php

$formattedValue = str_pad($value, 6, "0", STR_PAD_LEFT);

sprintf:

$formattedValue = sprintf('%05s', $value);
  • 0 is the character to pad 5 times. s specifies that it's a string.