saftutorials.com
PHP Constant Tutorial

PHP Constants is a predefined function of PHP. It is just like a variable but the difference is that PHP Constants used as a global variable and once it is defined it can not change during the execution of the script.

What is PHP Constants?

PHP Constants is a predefined function of PHP

Syntax of PHP Constants is define(name, value, case-insensitive).

PHP Constant Example

<!DOCTYPE html>
<html>
<body>
<?php
define("WISHES", "Hello John !");
?>
<p>This is a PHP Constant variable example : <?php echo WISHES;?></p></br>
<p>Same thing will print : <?php echo constant("WISHES");?></p>
</body>
</html>


The above code produces the following results

Outputs: This is a PHP Constant example: Hello John!

Same thing will print: Hello John!


PHP Constant Example (With case insensitive)

<!DOCTYPE html>
<html>
<body>
<?php
define("WISHES", "Hello John !", true);
?>
<p>This is a PHP Constant variable example : <?php echo wishes;?></p></br>
</body>
</html>


The above code produces the following results

Outputs: This is a PHP Constant example with case-insensitive: Hello John !


PHP Constant Example (AS a global variable With case-insensitive)

<!DOCTYPE html>
<html>
<body>
<?php
define("WISHES", "Hello John !", true);
function testGloabal (){
echo wishes;
}
?>
<p>This is a PHP Constant variable example : <?php testGloabal ();?></p>
</body>
</html>


The above code produces the following results

Outputs: This is a Constant as a global variable with case-insensitive: Hello John!


Find us on

Facebook Google Plus Twitter Pinterest YouTube

web statistic