Sunday 9 June 2013

CONSTANTS IN PHP

Till now, you must be wondering how to define constants in php. A variable can change it's value during the program execution, but a constant never changes it's value once it is assigned.
The following source code explains how to define a constant in php.

Source Code
/********************************************************************************/
<html>
                <head>
                                <title>Constants</title>
                </head>
                <body>
                                <?php
                                                $num1=90;
                                                define("num2",90);
                                               
                                                /* num1 is a variable
                                                                but num2 is a constant */
                                               
                                                $num1+=20;
                                                /* the following statement is not allowed
                                                as num2 is a constant
                                               
                                                num2+=20;
                                                */
                                ?>
                </body>

</html>
/********************************************************************************/
Note that the following program will not generate any output.

No comments:

Post a Comment