jeudi 23 novembre 2017

How do i rand string according to index size

I dont really no how to go about but it really pretty for me in achievement like each rand string to each index my tried code:

function rand_string($length) {
  $str="";
  $chars = "abcdefghijklmanopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  $size = strlen($chars);
  for($i = 0;$i < $length;$i++) {
   $str .= $chars[rand(0,$size-1)];
  }
  return $str;
 }
 $pcode = rand_string(4);
  for ($b = 0; $b<3; $b++)
   {
    echo $pcode[$b];
    }

expecting something like of example: 9cwm cZnu c9e4 in output can i achieve that in php? Currently with my code i got just a string from rand string in each index like 9cw




Aucun commentaire:

Enregistrer un commentaire