Chrome Extension

Define constant in PHP

<?php
    define(const_name, const_value); //SYNTAX
    define("month", "september");
?>
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

Constants can only be changed when initialize. In PHP you can define a constant by using the define() function which takes two required parameters constant name and constant value and one optional parameter case insensitive.

A constant is global means it can be accessed anywhere from the script once initialized and you also don't need to add the '$' keyword before the variable name to define a constant.

Example:

<?php
   define("firstname", "John");
   echo firstname;

   define("fruits", ["banana", "apple", "papaya"]);
   echo fruits[1];
?>
Was this helpful?
0 Comments
Join Devsheet Ask a Question