Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

PHP Constant tutorial with practicle example

PHP Constant tutorial with practicle example

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;
?>

 

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’,”);
?>
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments