Sunday 11 February 2018

PHP Constants

Constants are fixed that once they are defined they cannot be changed .
Constants are name or identifier that can't be changed during the execution of the script.
Rules:
It can be started with letter or underscore only.
PHP constants should be defined in uppercase letters
It can be defined by 2 ways:
Using define () function
Using const keyword
define()
Syntax:
    define(name, value, case-insensitive)  
name: specifies the constant name
value: specifies the constant value
case-insensitive: Default value is false. By default it is case sensitive.
Example 1:
     <?php  
      define("MSG","LearningPoint92");  
        echo MSG;  
       ?>  
Output:
LearningPoint92


Example 2:
        <?php  
        define("MSG","LearningPoint92",true);//not case sensitive  
        echo msg;  
    ?>  
Output:
LearningPoint92


 Example 3:
     <?php  
    define("MSG","LearningPoint92",false);//case sensitive (It provides error)
    echo msg;  
     ?>  
    Output:
     error
Notice: Use of undefined constant msg - assumed 'msg'.


const keyword
const keyword defines constants at compile time.
It is always case sensitive.
Example:
 <?php  
const MSG="LearningPoint92";  
     echo MSG;  
        ?>  
Output:
LearningPoint92

No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...