constant() function in PHP


The constant() function returns the value of a constant.

Syntax

constant(const)

Parameters

  • const − The name of the constant to check

Return

The constant() function returns the value of a constant and NULL if the constant is not defined.

Example

The following is an example that defines a constant.

 Live Demo

<?php
   define("myConstant","This is it!");
   echo constant("myConstant");
?>

Output

The following is the output.

This is it!

Updated on: 27-Jun-2020

188 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements