Pass variable int to string

0

Sorry for the question I asked, but I tried to pass a numeric variable to a string, but it does not take results. For example, in my database I have a field called "plano" type varchar and I need to save it in this way 088, but when I print the varible it only takes me 88, my code bit is like this

$nw="0";  
$codigo=$nw."".$plano[0]->plano; 

I must put something that I'm missing, so I can take the 0 that I need and save 088 and not 88.

Thanks

    
asked by Karli 16.11.2018 в 13:25
source

1 answer

1

If you need to add zeros to the left you can use the str_pad () function:

<?php
  $input = 88;
  echo str_pad($input, 3, "0", STR_PAD_LEFT);  // produce "088"
  echo str_pad($input, 3, "0", STR_PAD_RIGHT);   // produce "880"
?>

Or you can also have it saved with the leading zero because your field in the database in VARCHAR . And at the time of printing it should show equal "088"

    
answered by 16.11.2018 в 15:08