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();
?>

Tools:

Crypto Currency

PHPKIDA provides free online the best real-time crypto market price, news, predictions, index with graphs & historical data for 2000+ coins including bitcoin, ethereum, & altcoins from major cryptocurrency exchanges.

Visite Tool

Icon Generator

PHPKIDA provides free online icon generator. Our icon generator help you to edit, modify, resize and customize icon for your website and applications. Convert to a shap you like add icon border, you can change icon border color, border size, background color, icon shadow, icons color, icon size in your own way and save it as a png image.

Visite Tool

Youtube Video Downloader

PHPKIDA provides Free online YouTube video downloader to download YouTube videos quickly in MP4, 3GP, and more. Search your video and free fast download youtube videos.

Visite Tool

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.