Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.