phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP Constants: Introduction

Tag: Constants   Category: PHP Basic
post: 08 Mar 2008 read: 784


PHP Constants Step By Step Tutorial: Constant is an expression which have a value remain means that it is not change during the program/script execution. Constant is also called with the term of literal. Constant is usually used to assign value remain at calculation.

Note: Constant have the global characteristic, it means that constant can be accessed from any part in script without the abusively scope access.

To define a constant, you can use the function of define(). Only data type of scalar (boolean, integer, float, and string) which can be used as the data type of constant. The identifier name for constant is mould and declare without early with the dollar sign($).

Pay attention to the example of using constant at script as following:

File name: konstanta.php


<html>
<head>
<title>Using Konstanta</title>
</head>

<body>
<?
  define ("interest", 0.12); // constant
  $save = 50000000;
  $saving = $save + ($save * interest); 
  printf ("interest = %s"."<br>", interest);
  printf ("save = %s "."<br>", $save);
  printf ("saving = %s"."<br>", $saving);
  echo ("<h3>try to alter the value 
  of interest konstanta</h3>");
  $interest = 0.15;
  // mould interest as constant
  printf ("interest = %s"."<br>", interest);
  // mould interest as variable
  printf ("interest = %s"."<br>", $interest);
?>
</body>
</html>
php constant

In the example of the script above, the changes of the $interest constant value and 0.15 is not have an effect when mould as constant.



Series this article:
PHP Operators: Introduction
PHP Operators: Arithmetic Operators
PHP Operators: Assignment Operators
PHP Operators: Assignment Operators Table
PHP Operators: Bitwise Operators
PHP Operators: Relation Operators
PHP Operators: Ternary Operator
PHP Operators: Error Control Operator
PHP Operators: Execution Operator
PHP Operators: Increment or Decrement Operator
php Operators: Logic Operator
PHP Operators: String Operator
PHP Operators: Array Operator
PHP Operators: Object Operator
PHP Operators: Operator Priority
PHP Constants: Introduction

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Joomla: Fast Road to Understand Component Programming
Chart: How to Build Cool Animation Real Time Chart
Email: Send Attachement Mail
SMS : Sending SMS with PHP and ActiveXperts (Part 1)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


624
posting