Hi am using the following to gen a 4 char numeric
 $this->pin = rand(0000,9999)
however if the result is 0435 the leading zero is omitted. How can I keep the leading zero in the result?
Hi am using the following to gen a 4 char numeric
 $this->pin = rand(0000,9999)
however if the result is 0435 the leading zero is omitted. How can I keep the leading zero in the result?
 
    
    You can also:
$number = rand(0,9999);
$this->pin = str_pad($number,4,0,STR_PAD_LEFT);
 
    
    An integer is not a string, so you can't have a leading zero! :-P However you can do:
function zfill($str,$n){
  $ret = $str;
  while(strlen($ret)<$n){
    $ret = '0'.$ret;
  }
  return $ret;
}
$this->pin = zfill($this->pin, 4);
