AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL
HTML Tutorial

PHP Constant


<< Previous Page
PHP String Function
Next Page >>
PHP Operator Types

Constants does not need $ in front. But, as a convention of PHP programmers, constants are written in capital letters (A-Z) for easier observation.
The value of a constant can't be changed during the script.
A constant is declared using the define() function. The define() function has two arguments:
First, the name of the constant
Second, the value of the constant
In the following example you will see how a value is assigned to a constant and how we can call a constant

Note: Unlike variables, PHP constants are automatically global across the entire script.

Syntax:
define(name, value, case-insensitive)

Example 1: Create a PHP constant with a case-sensitive name:
<?php
define ("GREETING", "Welcome to AgerNic.com/!");
echo GREETING;
?>

Constant with a case-insensitive name. How to create?



PHP constant with a case-insensitive name:

Example 2:
<? Php
define("GREETING", "Welcome to AgerNic.com/!", true);
echo greeting;
?>
Output: Welcome to AgerNic.com/!

Constants are global.


PHP Constants are automatically global and can be used throughout the PHP script.

Example 3:
<?php
define ("GREETING", "Welcome to AgerNic.com/!");
function phpTest() {echo GREETING;
}
phpTest();
?>

<< Previous Page
PHP String Function
Next Page >>
PHP Operator Types



PHP 5 Constants - php tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


Home
PHP Introduction
PHP Install
PHP Syntax
PHP Variables
PHP Echo and Print
PHP Data Types
PHP String Function
PHP Constants
PHP Operator Types
PHP If Else and Elseif
PHP Switch
PHP While Loops
PHP Loop For Do Foreach
PHP Array
Convert Array to String
PHP Function
PHP GET and POST
PHP Date/Time Functions
PHP Login
PHP Delete Element
PHP eregi_replace()
PHP mysql_query()
PHP Errors to Display
PHP Loop For Do Foreach

PHP forms
PHP Form Example
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.