Jump to content

undefined variable: parola


I-AM-OBODO

Recommended Posts

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
?>

Link to comment
https://forums.phpfreaks.com/topic/261627-undefined-variable-parola/
Share on other sites

		$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.

		$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

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.