I-AM-OBODO Posted April 26, 2012 Share Posted April 26, 2012 hi all, pls I dont know why am getting this error undefined variable: parola. but the script runs thanks <?php $my_array = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "0", "1", "2", "3", "4", "5"); for ($i=0; $i<=5; $i++) { $random = array_rand($my_array); //this generates the random number from the array $parola .= $my_array[$random]; //here we will display the exact charachter from the array } echo $parola; // printing result ?> Quote Link to comment https://forums.phpfreaks.com/topic/261627-undefined-variable-parola/ Share on other sites More sharing options...
kicken Posted April 26, 2012 Share Posted April 26, 2012 $parola .= $my_array[$random]; That line is the same as $parola = $parola . $my_array[$random]; which means it is trying to first read the existing value of $parola before setting it to the new value. On your very first iteration of the loop, $parola does not exist because you've never defined it anywhere. Because it does not exist when php tries to read it you receive that notice. Add $parola = ''; before your loop to define the variable first. Quote Link to comment https://forums.phpfreaks.com/topic/261627-undefined-variable-parola/#findComment-1340624 Share on other sites More sharing options...
I-AM-OBODO Posted April 26, 2012 Author Share Posted April 26, 2012 $parola .= $my_array[$random]; That line is the same as $parola = $parola . $my_array[$random]; which means it is trying to first read the existing value of $parola before setting it to the new value. On your very first iteration of the loop, $parola does not exist because you've never defined it anywhere. Because it does not exist when php tries to read it you receive that notice. Add $parola = ''; before your loop to define the variable first. thanks. its okay now. had to define parola before the functions Quote Link to comment https://forums.phpfreaks.com/topic/261627-undefined-variable-parola/#findComment-1340640 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.