PHP Constants Explained: Definition, Types and Examples
Constants used in php
PHP coding manam oka website ki leka application ki lopala em process jaragali ani chupisthundi. Manam Facebook anukunte, andulo PHP coding use chestharu. Andulo manaki login ID, name, photo, postlu chupinchadaniki PHP vadatharu. Appudu server ki ardham avuthundi. PHP coding tho user ki em chupinchalo adi server lo save avuthundi.
Manam PHP ani pilusthamu kani asalu name Hypertext Preprocessor. PHP full form idi. PHP ni easy ga nerchukovachu, mariyu website build cheyadaniki kuda speed ga cheyavachu.
Constant in php:
Once we assigned any value in constant we cannot change that value in execution of php code .
There are two types of constants:
1.define
2.const
Define():Define is used in functions.so, that we are assigning a variable values for identifiers.these define function working at runtime.Define function is easy and flexible for the users.Syntax for constantdefine(“identifier”, “variable _value”);
Program:
<?phpdefine(“welcome”, “one siddharth.co.in”);echo welcome.”\n”;//This a case sensitive constant.define(“Welcome”,”To the php world”,true);echo welcome;//This is not a case sensitive constant.Differences is we are using true on the define function?>
Output:
one siddharth.co.inTo the php world.
Explanation:-
Php code lo manam define function use chesi constant code rasam.aa define function kooda okati case Sensitive constant and inkokato case sensitive kaadu.rendu Ela use cheyalo differences ento php comment use chesi rasamu.
3.const
const is another type of define function.but the difference is here we are using const keyword.
This constant function is used at compile time not in runtime of the php code.
These are only case sensitive.
Syntax for const:
const Constant_name=”value”;Program for const using php:<?phpconst Variable=”hello friends”;echo Variable.”\n”;const Abc=”Welcome To the php world”;echo Abc;//This is case sensitive.so,we are writing constant name exactly?>
Output:-
hello friendsWelcome To the php world
Explanation:
Php lo constant anedi inko keyword .manam deenni const ane danitho start chestam paina ichina syntax use chesi code rastamu.akkada \n ivvatam valan output anedi next line loki velthundi.
Constant name em aithe istamo adhe echo lo print cheyamani adagali.case sensitive kabatti letter small or capital edhi iste adhe ivvali.
2 thoughts on “PHP Constants Explained: Definition, Types and Examples”