‫Okay.
‫So now we're going to look at environment variables.
‫And we're going to look at the globals super global.
‫Now there is an env super global.
‫But in many in many configurations including mine we can't directly access it or we can access it but
‫we can't add to it.
‫Instead we have some functions that we can use to add environment variables and get environment variables.
‫And these are variables or values that aren't just for your PHP script.
‫They're system wide.
‫So they're actually things that could be accessed within other programming languages and frameworks
‫and stuff like that.
‫So I just have just a template here, and you can get this from the starter files, and we're going
‫to just go right above it and open up some PHP tags.
‫And the first thing I want to show you is how to set an environment variable with a function called
‫put env.
‫So we're going to say put env and this takes in a string.
‫And we're going to format it like the variable name.
‫So for instance let's say we were we had our database credentials and we want DB host.
‫So we would say db host equals.
‫And then whatever we want that value to be.
‫So we'll set local host okay.
‫Let's say we want it to have a DB user.
‫We'll say DB user and I'll set that to root.
‫All right.
‫Now to get these we could use the get env.
‫And it's all lowercase these functions.
‫So get env.
‫And then I can say db underscore host.
‫Actually instead of echoing it out I'm going to put it into a variable called host.
‫And then I'll put the user.
‫Into a variable called user, let's say db host.
‫I'm sorry.
‫DB user.
‫And then down below here right under these strong tags let's open up our PHP syntax.
‫We use the shorthand and we'll output the host.
‫And then down here.
‫Well, I'll put the user.
‫All right.
‫So I'll go ahead and reload.
‫And now you can see local host and root.
‫All right.
‫Now in all honesty I don't use these all that much.
‫But there may be reasons why you need to work with environment variables.
‫If things like this like database credentials, I usually just put in a constant and I make it accessible
‫throughout my script wherever I need it.
‫Um, as far as seeing all of your environment variables on your system, you can use get env but not
‫pass anything into it.
‫So for instance, if I say var, let's do a var dump of get env.
‫And I'm just I'm going to blur my screen just because I'm not sure if some of this stuff may be a little
‫bit, a little bit suspect that I don't want, you know, the world to see, but you'll see all the
‫all the environment variables on your system, including the one, the ones that we just created.
‫So you should see the DB host and db user which I have down at the bottom.
‫But you can access some of this other stuff too, like let's say home.
‫If you want to get the the home value home path, we could say get env.
‫And then pass in home.
‫And if you reload that, you should see at the very top.
‫Let me just comment this out.
‫You can see the home directory.
‫All right.
‫So those are environment variables.
‫Now let's look at.
‫Uh, let's look at the globals super global.
‫And what this does is it, it gives us an associative array that contains references to all the variables
‫defined in the local scope.
‫I'm sorry, the global scope of the script.
‫So if I have a variable here called foo and I set it to let's say global variable.
‫Right.
‫And then let's say we have a function called test.
‫And I don't use this very much.
‫This globals super global.
‫So I'm just using the example from the documentation.
‫So in test we can define foo here which will then be a local.
‫Variable.
‫And if I wanted to access that global one.
‫There's many ways I can do this, but one of them is with the global super global.
‫So let's say we'll echo out.
‫Global.
‫Variable.
‫And then let's concatenate.
‫Now it's with this.
‫It's a little confusing because it's not underscore globals.
‫It's just money sign globals like that.
‫And then let's say foo.
‫Okay.
‫And then I'll come down here and let's run test.
‫Actually, I'll echo out the local one as well.
‫We can just copy this down and let's say.
‫Local variable.
‫And then here we'll just use.
‫Full.
‫All right, so if I reload that, we get global variable.
‫Uh.
‫Actually, that's not set.
‫Let me just add a line break here because it's a little less confusing.
‫And let's see.
‫Yeah.
‫Global variable.
‫Maybe I shouldn't have called it the same thing as the heading here, but let's say foo.
‫Global.
‫And this one.
‫Let's say fu.
‫Local.
‫Okay.
‫And if I were to come out outside of the test and change foo.
‫And just change it to.
‫Hello.
‫And then if I reload that, you'll see that global variable.
‫The value is now.
‫Hello.
‫So you can use this to access global variables from wherever.
‫All right.
‫Now like I said I don't really use either of these very much.
‫You probably won't either.
‫It depends on on what you're doing.
‫I want to let you guys know all the different super globals that are available.