Jump to content

For loop


harkly

Recommended Posts

I have this code that generates a random string of numbers & letters. It works just fine but I need help with taking the variable $newPassword out of the for loop. I ultimately want to be able to email the $newPassword.

 

Code that works ...

<?php 
for ($i=0; $i<7; $i++) { 
    $d=rand(1,9)%2; 
    $newPassword= $d ? chr(rand(65,90)) : chr(rand(48,57)); 
echo $newPassword; 
} 
?>

 

 

Would like to be able to echo it outside of the for loop, right now it just echos 1 number or letter....

<?php 
for ($i=0; $i<7; $i++) { 
    $d=rand(1,9)%2; 
    $newPassword= $d ? chr(rand(65,90)) : chr(rand(48,57)); 
} 

echo $newPassword; 

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/202290-for-loop/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.