New course! Every coder should learn Generative AI!
Try a free lesson+ 5
I need some help in php....
https://code.sololearn.com/wWvSYAQ21gRr/?ref=app There is a Random Password Generator and strength checking code... There are many parts which could be improved. Can you tell me how multiple random passwords $pass1, $pass2, $pass3 could be putted in single loop of $pass???
4 Answers
+ 1
You mean this ?
$pass1="";
$pass2="";
$pass3="";
$plength=10;
for($i=0;$i<$plength;$i++){
$pass3.=chr(rand(33,122));
$pass2.=chr(rand(33,122));
$pass1.=chr(rand(33,122));
}
+ 2
Yes, somehow that is helpful.
But exactly, if there is some way to make $pass along with loop of $n, where $n could be taken as 1, 2, 3...
Some kinda
for($n=0;$n<3;$n++){
$pass.$n="";
$plength=10;
for($i=0;$i<$plength;$i++){
$pass.$n=chr(rand(33,122));
}
}
Is that possible somehow?
+ 1
Ahh Okay there is a way:
for($n=1;$n<=3;$n++){
${"pass" . $n} = "";
$plength=10;
for($i=0 ; $i<$plength ; $i++){
${"pass" . $n} .= chr(rand(33,122));
}
}
i.e. use curly braces to wrap the variable name ${}
PS: For the thing you are doing, I would prefer creating an array of n length.
- 1
h eart's