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: 2020-06-27T08:50:44+05:30

242 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements