Hello Friend how are you i hope you all are doing well. Today in this post we will learn about constant like What is constant , how to define constant, Syntax of constant, program using constant and What is keywords and some important keyword used in PHP. If you want to learn PHP in very simple easy way then this post will help you definitely.
👉Constant Definition
1.An element of program whose value can not be changed at the time of execution of script is called constant.
2.PHP constant starts with a letter or underscore.
3.PHP constant does not start with dollar sign($).
4.No space are allowed in constant name.
5.Constants are global in nature.
👉define() function
1.It is a predefined function of php.
2.It is used to set a variable with value which can be used anywhere in the program like global variable.
3.It has three parameter variable name,variable value,case-sensitivity.
4.Its value can not be modified means we can say that it assigns a constant value to the variable.
👉Syntax
define(constant_name,constant_value,case_sensitivity);
1.constant_name:It is the name of the constant.
2.constant_value:It is the value of the constant.
3.case_sensitivity:Case-sensitivity part of define function is optional. by default the variable name is case sensitive but if we put true value at the place of case-sensitivity then it becomes insensitive.
👉Case Sensitive Constant
In this example the constant name (NAME) is case sensitive.
<?php define("NAME", "Rocky Singh"); echo NAME; /* Output Rocky Singh */ ?>
👉Case Insensitive Constant
Just put true in place of case-sensitive parameter to make constant insensitive.
<?php define("NAME", "Rocky Singh",true); echo NAME."<br>"; echo Name."<br>"; echo name."<br>"; /* Output Rocky Singh Rocky Singh Rocky Singh */ ?>
👉Sum of two number
<?php define('FIRST',50); define('SECOND',100); define('SUM',FIRST+SECOND); echo "Sum Of two numbers=".SUM; /* Output Sum Of two numbers=150 */ ?>
We can also assign the constant value to a variable.
<?php define('FIRST',50); define('SECOND',100); $sum=FIRST+SECOND; echo "Sum Of two numbers=".$sum; /* Output Sum Of two numbers=150 */ ?>
👉Keywords in PHP
1.The word which is pre-defined in the library is called keyword.
2.It's functionality is also pre-defined.
3.Keyword can not be used as a variable, function name ,class name or as an any identifier.
4.Example of keywords are abstract , break , const , continue , function etc.
👉Some important keywords in PHP
abstract,and,array(),as, break ,case,catch, class clone, const, continue ,declare, default die(), do, echo ,else, elseif, empty(), if , include ,switch , for , while , public , private , protected , static , try , catch , throw etc
Request:-If you found this post helpful then let me know by your comment and share it with your friend.
0 Comments