Monday, 20 May 2013

php constant


PHP Constant

define() -

    In PHP, we declare constant by define() or The define() function defines a constant.
    Syntax
    <?php define(name,value,TRUE or FALSE(optional)); ?>
    ParameterDesryption
    NameRepresents the name of constant
    valueRepresents the value of constant
    OptionalIn optional parameter we use true and falsevalue if we enter TRUE constant remain case-insensitive otherwise constant will case-sensitive.

    Example

    <?php define('test','Hello how are you?'); echo constant('test'); ?>
    Output :
    Hello how are you? 

    Example

    <?php define('rex','my name is rex'); echo rex; ?>
    Output :
    my name is rex

    Note -

    PHP constants are similar as php variable and little more permanent.
  • The value of constant can not changed after assigned.
  • It can hold value only strings and numbers.
  • we do not use $ sign with constant name.
  • It can hold value only strings and numbers.

No comments:

Post a Comment