php constants

php constants

Constants is a identifier that once defined in program or page they cannot be changed or undefined.
A constant is an identifier for a simple value. The value cannot be modified during the script’s execution. A valid constant name starts with a letter or underscore (don’t use dollar($) sign before the constant name) and by convention constant identifier are always uppercase.

Note: Constants are automatically global across the entire script.

Constants are defined by using the define() function or by using the const keyword outside a class definition as of PHP 5.3.0. The name of the constant and the value must be placed within the parentheses. After defining it can never be changed or undefined. Only scalar data i.e. boolean, integer, float and string can be contained in constants.

Syntax PHP Constant

define(name, value, case-insensitive)

define() function Parameters:
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

The example below creates a simple constant with a case-sensitive name:

<?php
define("SIMPLE", "Hi, How Are You!");
echo SIMPLE;
?>

The example below creates a simple constant with a case-sensitive name:

<?php
define("SIMPLE", "Hi, How Are You!", true);
echo simple;
?>

Global Constants

You know constant automatically work as a global variable.

<?php
define("SIMPLE", "Hi, How Are You!");

function SimpleTest() {
    echo SIMPLE;
}
 
SimpleTest();
?>

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Free online tool to download Instagram videos, photos and save Instagram videos, photos to your device. It's free & easy to use.

Download Now

CURRENCY CONVERTER

Our real time currency converter calculator will convert your money based on current values from around the world. It's free & easy to use.

Convert Now

ROBOST.TXT GEN.

Create robots txt file that help search engines to crawling and indexing your site with help of our free online Robots.txt Generator tool.

Create Now

HTML MINIFIER

Free online tool to minify or compress html code and reduce the size of html code in few clicks. It's free & easy to use.

Minify Now

CSS MINIFIER

Free online tool to minify or compress css code and reduce the size of css code in few clicks. It's free & easy to use.

Minify Now

JAVASCRIPT MINIFIER

Free online tool to minify or compress javascript code and reduce the size of javascript code in few clicks. It's free & easy to use.

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.