How to define global constant in php

Create + use constants in entire php program script inside function scope.

Constants are automatically build as globally so web developer doesn’t need to specify any extra keyword to make its constant as global constant. If developer can specify a constant at the top of php program then it can easily call inside below function scope. So here is the complete step by step tutorial for How to define global constant in php.

android-project-download-code-button

How to define global constant in php.

Code for Global_constant.php file.

 <?php

//Defining constant.
define("NAME", "PHP & ANDROID TUTORIALS", true);

//Defining function.
function test()
 {
 //Printing constant value on screen using echo.
 echo NAME;
 }

//Calling function.
test();

?>

Screenshot:

How to define global constant in php

Click here to download How to define global constant in php project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *