/    Sign up×
Community /Pin to ProfileBookmark

initialize variable?????

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:

[code=php]
$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
}[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@knowjNov 04.2007 — 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
Copy linkTweet thisAlerts:
@mitchellauthorNov 04.2007 — thanks
Copy linkTweet thisAlerts:
@NogDogNov 04.2007 — In this case, I would normally initialize it as an empty array:
[code=php]
$userarray = array();
[/code]
×

Success!

Help @mitchell spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...