-3

I'm trying to printf a variable with some 000 on the left side but only print the 000 and no print the variable.

$activePlayers1 = array(3)
numero = $activePlayers1[$i];        
printf('000',$numero);

The result of this is 000 and no print the 3.

Nick
  • 123,192
  • 20
  • 49
  • 81

2 Answers2

1

It should be like this

 $activePlayers1 = array(3)
     numero = $activePlayers1[$i];        
     printf('%d',$numero);
Maxim
  • 2,041
  • 5
  • 15
1

If you are trying to pad with zeros, you should use a padding specifier:

<?php

$numero = 5;
printf("%'.09d", $numero);

?>

yields

000000005

Try it yourself

The d is a type specifier, used to treat the variable value as an integer and display it as a decimal, and you can find the full list of type specifiers under the sprintf documentation.

d - the argument is treated as an integer and presented as a (signed) decimal number.

Alex W
  • 35,267
  • 10
  • 97
  • 106