Constant: Constant refers to fixed value that does not change the value during the execution of program. Constant are defined using PHP’s define () function which accept two arguments. The $ prefixed is not required for constant.A simple Example :
<?php
//define constant
define('PI',3.14);
$r=5;
//use constant
$area=PI*$r*$r;
echo "Area of circle=".$area;
?>
//define constant
define('PI',3.14);
$r=5;
//use constant
$area=PI*$r*$r;
echo "Area of circle=".$area;
?>
Result - 78.5
Practical example:
This script is used for data base connection.
<?php
define('MYSQL_HOST','localhost');
define('MYSQL_USER','root');
define('MYSQL_PASS','');
?>
define('MYSQL_HOST','localhost');
define('MYSQL_USER','root');
define('MYSQL_PASS','');
?>
Tidak ada komentar:
Posting Komentar