Jan 19, 2021, 02:56 AM

News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!


Constants

Started by VelMurugan, May 20, 2009, 10:34 PM

previous topic - next topic
Go Down

VelMurugan

Constants

Constants just as variables are used to store information. The main difference between constants and variables is that constant value can not be changed in the process of running program. It can be mathematic constants, passwords, paths to files, etc. By using a constant you "lock in" the value which prevents you from accidentally changing it. If you want to run a program several times using a different value each time, you do not need to search throughout the entire program and change the value at each instance. You only need to change it at the beginning of the program where you set the initial value for the constant.

Have a look at the example where we use the define function to set the initial value of a constant:

Code: [Select]
<?php
// first we define a constant PASSWORD
define("PASSWORD","admin");

echo (
PASSWORD);                  // will display value of PASSWORD constant,  i.e. admin
echo constant("PASSWORD");   // will also display admin
echo "PASSWORD";                 // will display PASSWORD
?>


PHP also provides a number of built-in constants for you. "__FILE__", for example, returns the name of the file currently being read by the interpreter. "__LINE__" returns the line number of the file. These constants are useful for generating error messages. You can also find out which version of PHP is interpreting the script using the "PHP_VERSION" constant.

Go Up
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:
Verification:
Please leave this box empty:

Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

shortcuts: alt+s submit/post or alt+p preview
IT Acumens Web Designing Chennai | GinGly :: Build your Personal Website | CineBuzz :: Cinema News | My Kids Diary :: Kids Memories Writing :: Book Website @ 349 Rs monthly
Copyright 2005 - 2020 :: IT Acumens :: All Rights Reserved. :: Sitemap
ITAcumens Discussion Forum with 2 lakhs post running for 15 years - Powered by IT Acumens Dedicated Server