Constants in PHP

In this tutorial we will learn about Constants in PHP. In last tutorial we learnt about variables in PHP. I hope now you would have clear idea about variables. As we learnt in last tutorial value of variable can be change through out the program. but on the other hand value of constants can not change. In simple words constants are also like variables but once constants get defined value of constants can not be change like variables.

Constants in PHP


With the help of constants we have store data which would not change in whole program for example store data like DB_username, DB_password or BASE_URL in constants. Constants help us to make sure that our data would not change through out the whole program even not by mistake from Programmer.

If you define any value in from Constant. The only way to change value is to change value where you define the constant for vary first time in program.

In PHP we can define Constants using define () function. This function accept two parameters first one is name of constant and second is value of constant. After defining constant you can access it any where in program by using its name. Check this example to understand constants more clearly.

Example





Share this tutorial with your friends on your social Media..

Constants in PHP Constants in PHP Constants in PHP Constants in PHP



Now You Can Follow All These Tutorials on Your Android Mobile Just Download This App.


Owlbuddy.com