How to validate a number of characters in a cycle and 'set' a value with PHP?

0

In php I get two parameters, the codigo and the cantidad , the codigo can be PDO0016890 and the cantidad can be 10000 which are the number of times the increase will be number of codigo .

  $code = $_POST['code'];
  $cant = intval($_POST['cant']);
  $nums = preg_split('/[^0-9]+/i', $code);
  $strings = preg_split('/[^a-zA-Z]+/i', $code);   
  $intN = $nums[1];

 for($i = 0; $i < $cant; $i++){
    echo json_encode($intN++);
  }

PROBLEM:
when you go through the arrangement in the first 'round' it shows 0016890 but from the second 'round' shows 16891 , 16892 , etc ..., that is to say it takes away the 00,

  

How could I validate that I do not remove those zeros?

    
asked by JDavid 21.11.2018 в 21:33
source

1 answer

1

It removes the zeros because when you increase it% PHP% transforms it completely.

If your number in the code will always be 7 digits you can increase it and add the missing zeros with str_pad

echo json_encode(str_pad($intN++, 7, "0", STR_PAD_LEFT));
    
answered by 21.11.2018 / 21:51
source