Jump to content


PHP variables

  • Please log in to reply
3 replies to this topic

#1 ryan.od

  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 30 October 2006 - 07:44 PM

How does PHP treat variables? What I mean is, if I set $auth = 1 in one script and then set $auth = 0 in another script, which value does the site recognize as the true value? Is each $auth unique to it's script (local) or are variables in PHP such as the $auth variable I am using global?



#2 roopurt18

  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 30 October 2006 - 07:51 PM

It depends on if the scripts include one another or what other pages include those scripts.
PHP Forms : Part I | Part II

JavaScript: Singleton


#3 jwk811

  • Members
  • PipPipPip
  • Advanced Member
  • 714 posts

Posted 31 October 2006 - 03:58 AM

on one of my scripts it just goes in order like if $var is first in the script that will have the value assigned to it until you get to $var = farther down and that will have a new value for the rest of the script (unless its changed again)

#4 Skatecrazy1

  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 31 October 2006 - 04:10 AM

Okay so basically, it's how jwk811 put it, but theres a little more to it.  To put it clearly:

let's say i have a variable named $str.

up at the top of my file, $str = "Eric Cartman";

let's say I want to change the value of $str later in my script:  $str = "Stan Marsh";

but also, using the "." operator, i could add things to a string: $str .= " and Kenny McCormick";

which would echo "Eric Cartman and Kenny McCormick"

plus, if you include a file that contains a variable in another file, the variable is accessible in the file you included it to.
fuck it or fight it

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users