Wednesday, July 3, 2024
HomeLanguagesPhpPHP constant() Function

PHP constant() Function

The constant() function returns the value of a constant. It also works with class constants. 

Syntax:

constant(constant)

Parameter Values:

  • constant: It is a required value that specifies the value of the constant.

Return Value: It returns the value of a constant if the constant is defined else returns NULL.

Note: It works on PHP 4.0 or newer versions.

Exceptions: If the constant is not defined, it throws an E_WARNING error. It gives a run time warning without script termination.

The following are the PHP programs to show the working of the constant() function.

Example 1: Case sensitive

PHP




<?php
  
// Define a constant
define("Home","Welcome to neveropen");
  
echo constant("Home");
?>


Output:

Welcome to neveropen

Example 2:  Case insensitive

PHP




<?php
  
// Define a case insensitive constant
define("GFGConstant","True denotes case-insensitive", true);
  
echo constant("gfgconstant");
?>


Output: 

True denotes case-insensitive

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

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments