Loading...

PHP Constants


In php a constant is a variable whose value can't be change through out the program.
constants are helpful in where we want that the value remains same through out the program for some reasons :
in php database application we want that the 'host' value reamins unchanged because if someone change the host value then the app produce some error or other type of issues may arise. so, in that case we want constant variable values in our php mysql app.

In php we can define constant variable by two ways :
-> by using const keyword.
-> by using define function.

the conventions used for constants in any programming language is to used in all uppercase letters in the constant name.
for example :
-> const HOST = "localhost";
-> define(constant_name, constant_value, case-insensitive ) //case sensitive is default in php
for example :
define("HOST", "localhost", case-insensitive);