Course Content
Introduction
PHP is an object-oriented scripting programming language that allows web developers to create dynamic and interactive web pages. PHP stands for Hypertext Preprocessor (PHP).
0/14
Control Statement
A control statement is a statement that determines whether other statements will be executed.
0/7
PHP for Beginners
About Lesson

Constants are PHP containers that remain constant and never change. Constants are used for data that is unchanged at multiple places within a program. Variables are temporary storage while Constants are permanent. Use Constants for values that remain fixed and referenced multiple times.

 

Rules for defining constant

PHP constants can be defined in 2 ways:

  • Using define() function
  • Using const keyword

 

Using define() function

define(name, value, case-insensitive)

name: Name of the constant

value: Value of the constant

case-insensitive: Whether a constant is case-insensitive, The default value is false.

 

Using const keyword

The const keyword defines constants at compile time. It is a language construct, not a function.

<?php
const MESSAGE = "Welcome to PHP";
echo MESSAGE;
?>