How do I initialise a variable once?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phpnitemare
Forum Newbie
Posts: 12
Joined: Sat Mar 28, 2009 1:14 pm

How do I initialise a variable once?

Post by phpnitemare »

hello,

I am trying to set a variable to 0 when the webpage first loads. Doing this in my index.php currently means the variable would contantly get reset changing the pointer variable back to 0. Even using the if statement below causes the same problem as without establishing pointzero to 0 the variable will not be initialised however the if statement will always be true. How can I build it so that pointer is only set to 0 once upon first website load?

Code: Select all

$_SESSION["pointzero"] = 0;
if($_SESSION["pointzero"] == 0) {
$pointer = 0;
$_SESSION["pointer"] = $pointer;
$_SESSION["pointzero"] = 1;
}
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How do I initialise a variable once?

Post by requinix »

Set the pointer to 0 only if it hasn't been set yet.
Post Reply