-1

How get the number with format is leading zero ex:01 and how to make format number like that my problem is from this query

$try= $this->login->get_id_child('00',3);
$count_try = count($try);
$id ="00";
$new = $id.$count_try;
echo $new;

the result from echo $new is 003

data in array $try=array(000,001,002) and try is count by $count_try the result is 3. but I want to make the result from $count_try is 03 so I can join that variable to my id so I can get $new=00003 but if the data in

$try=array(000,001,002,003,004,005,006,007,008,009);

so the value of $new is 0010

Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54
nanasjr
  • 207
  • 1
  • 2
  • 12

2 Answers2

1

You can use str_pad -

echo str_pad($new, 2, "0", STR_PAD_LEFT);

str_pad()

Update

    $count_try = 10;
    $new = str_pad($count_try, 4, "0", STR_PAD_LEFT);
    echo $new;
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
-1

Try this :

$id ="0010";
$new = (int) $id + 1;
$new = str_pad($new, 4, "0", STR_PAD_LEFT);
echo $new; //0011
user2226755
  • 12,494
  • 5
  • 50
  • 73