Constant in PHP

Advertisements

Variable in PHP DataType in PHP

Constant in PHP

Constants are name or identifier that can't be changed during the execution of the script. In php constants are define in two ways;

  • Using define() function
  • Using const keyword

In php decalare constants follow same rule variable declaration. Constant start with letter or underscore only.

Create a PHP Constant

Create constant in php by using define() function.

Syntax

define((name, value, case-insensitive)
  • name: Specifies the name of the constant
  • value: Specifies the value of the constant
  • case-insensitive: Specifies whether the constant name should be case-insensitive. Default is false

In below example we create constant with case-sensitive

Example of constant in php

<?php
define("MSG","Hello world!");  
echo MSG;  
?>

Output

Hello world!

In below example we create constant with case-insensitive

Example of constant in php

<?php
define("MSG","Hello world!", true);  
echo msg;  
?>

Output

Hello world!

Define constant using cons keyword in php

The const keyword defines constants at compile time. It is a language construct not a function. It is bit faster than define(). It is always case sensitive.

Example of constant in php

<?php
cons MSG="Hello world!";  
echo MSG;
?>

Output

Hello world!

Variable in PHP DataType in PHP

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements