• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Techgoeasy

Techgoeasy

Learn Oracle, PHP, HTML,CSS,Perl,UNIX shell scripts

  • Home
  • Oracle
    • Oracle database
    • Oracle Ebusiness Suite
    • Oracle weblogic
    • Oracle Performance Tuning
    • Oracle Hyperion
    • Oracle Cloud Tutorials
  • SQL
  • interview questions
  • Linux
  • PHP and HTML
  • Downloads
  • General
Home » Web development » PHP » How to define constant in php

How to define constant in php

October 18, 2015 by techgoeasy Leave a Comment


How to define constant in php

Constants in PHP

(1) A constant is a name or an identifier for a simple value. It is defined using the define function and it does not start with $ sign

Syntax
define(name, value, case-insensitive)

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

Example
<?php
define("DBNAME", TECH);
echo DBNAME;
?>

(2) A constant value cannot change during the execution of the script. By default, a constant is case-sensitive. By convention, constant identifiers are always uppercase. A constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. If you have defined a constant, it can never be changed or undefined.

(3) A constant differ from variable as variable value can be changed across the execution while constant value cannot

(4) Constant value are global across the execution.

<?php
define("DBNAME", TECH);
function checkdbname() {
print DBNAME;
}

checkdbname();
?>

(5) constant value are retrieved using constant() function or simply we can use echo

<?php
echo "DBNAME";
echo "constant(DBNAME);
?>

(6) PHP defined some predefined constants like LINE,FILE, CLASS

(7) You can define constant as arrays starting PHP 7 as

<?php

define("DB", [
"TECH",
"GO",
"EASY"
]);
echo DB[0];
?>

Hope you like post on How to define constant in php

Also Reads
How to run php file in windows
uses of PHP
first php program
https://en.wikipedia.org/wiki/PHP


Filed Under: PHP, Web development Tagged With: Constant and echo-print statement

Reader Interactions

Leave a Reply Cancel reply

Primary Sidebar

Top Posts & Pages

  • How to check Tablespace in Oracle -Size ,Free space,datafiles ,growth
  • how to check all constraints on a table in oracle
  • Query to check table size in Oracle database
  • Oracle dba interview questions and answers
  • Oracle Indexes and types of indexes in oracle with example



Subscribe to our mailing list

Enter your email address to subscribe to this blog and receive notifications of new posts by email

Recent Posts

  • How to run Autoconfig on Patch system in R12.2
  • Admin scripts in R12.2 Ebuisness Suite
  • Timezone settings in Oracle database
  • how to enable trace in oracle apps r12
  • Transparent Data Encryption Queries

Copyright © 2021 : TechGoEasy

  • Hire me
  • Privacy Policy
  • Contact Us
  • New? Start Here
  • About Us