Click to See Complete Forum and Search --> : initialize variable?????


mitchell
11-03-2007, 07:59 PM
i have a script that gets users information witch someone has helped me with but they have put a comment "// initialize variable" and can i ask what i suppposed to put there? thanks

heres the bit of the code:


$query = "SELECT * FROM `users`"; // get all user information
$result = mysql_query($query);
$userarray; // initialize variable

while($row = mysql_fetch_array($result))
{
$userarray[$row['x'] . ',' . $row['y']] = true;
// load all the user info we need into an array
}

knowj
11-03-2007, 08:16 PM
in some languages you have to initialize your variables before you can use them (i think this is the case with javascript if i remember correctly)

But if i am right it will also make this variable NULL by using $userarray; in php4 with super_globals on this would help prevent anyone from injecting data into the script.

someone please correct me if im wrong its been a long time since i've used a system with super globals on

mitchell
11-03-2007, 10:26 PM
thanks

NogDog
11-04-2007, 12:02 AM
In this case, I would normally initialize it as an empty array:

$userarray = array();