Thursday, October 23, 2025
HomeLanguagesPHP define() Function

PHP define() Function

The define() function is basically used by programmers to create constant. Constants in PHP are very similar to variables and the only difference between both are the values of constants can not be changed once it is set in a program. 

define() returns a Boolean  value. It will return TRUE on success and FALSE on failure of the expression.  

Syntax:

define(string $constant, mixed $value, bool $case_insensitive);

Parameters:

  • $constant: It is of String type that describes the name of the constant and is a required parameter. 
  • $value: It is of mixed type and it describes the Value of the constant and is required in parameter
  • $case_insensitive: It is of a boolean type that describes whether the name of the constant can be case-sensitive or not and it is an optional parameter.

Return Value: This method returns a boolean value TRUE on success and FALSE on the failure of the expression.  

Example 1: In this example, we have created a constant namely GREETINGS  and its value is Hello GFG and the name of the constant is case-insensitive by using define() function.

PHP




<?php
    define("GREETINGS", "Hello GFG.", true);
    echo GREETINGS;
?>


Output

Hello GFG.

Example 2: In the below example, we have created a constant named as LANGUAGES which consist of an array as it’s value and the name of the constant is case-sensitive.

PHP




<?php
    define('LANGUAGES', array(
    'C',
    'C++',
    'JAVA',
    'PYTHON'
    ));
  
    echo LANGUAGES[3];
?>


Output

PYTHON

Reference: https://www.php.net/manual/en/function.define.php

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS