Environment variables is the array of the values related to environment in which your application is running, just like OS, Computer Name, etc. PHP has provided few functions to deal with these variables. I mean we can add, remove variables from default values.
Here we will see how to add new environment variables using PHP, how to get value of environment varible in PHP, how to remove environment variable in PHP and how to change the value of the environment.
We have ready PHP core function to add new environment varible. But make a note that, variable added using this method will only available during the script execution. It will get removed after the script execution is completed.
This function takes only one parameter as a Key=Value pair. Have a look at below code to see how it works.
Just like adding the new value, getting the environment variable value is also very simple. You just need to call one PHP core function and pass the key of the varible. Have a look at below code block for the same:
For editing and removing the environment variable you need to use the same function which we used while creating the environment. Have a look at below code block for the same:
In above code block you can see that, to remove the variable you just need to insert it blank. :)
Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.
View all posts by: Avinash