-->

  • PHP constant - constant Array - constant global






    Constant is an identifier with a simple value whose value cannot be changed during script running.

    A valid Constant name begins with a letter and underscore  (no $ sign before the constant name).

    Note: Unlike variables, constants are automatically global across the entire script. PHP constant - constant Array - constant global


    Syntax


    define (name, value, case-sensitive)


    Parameterts :


    • name : Specifies the name of the constant
    • value : Specifies the value of the constant
    • case-sensitive : Specifies the wheteher the constant name should be case-insensitive. Default is false.

    ( NOTE : To create constant, use the define() funciton )




    Example 

    Create a constant with a case-sensitive name:



    // case-sensitive constant name

    define("GREETING", "Welcome to kumaratuljaiswal.in");

    echo GREETING;



    ?>



    </body>
    </html>





    Welcome to kumaratuljaiswal.in!





    Example 

    Create a constant with a case-insensitive name:



    // case-insensitive constant name

    define("GREETING", "Welcome to kumaratuljaiswal.in", true);

    echo GREETING;



    ?>



    </body>
    </html>





    Welcome to kumaratuljaiswal.in




    PHP Constant Arrays

    In PHP7, you can create an Array constant using the define() function.


    Example 

    Create a constant with a case-insensitive name:



    define("person", [
      "HackerBoY",
      "Atultheahacker",
      "Kumar"
    ]);
    echo cars[0];



    ?>



    </body>
    </html>




    HackerBoY







    Constants are Global

    Constants are automatically global and can be used across the entire script.


    Example


    This example uses a constant inside a function, even if it is defined outside the function:





    define("GREETING", "Welcome to hackingtruth.in");

    function myTest() {

    echo GREETING;

    }

    myTest();




    ?>



    </body>
    </html>





    Welcome to hackingtruth.in




    Video on This Topic :- Soon


    I hope you liked this post, then you should not forget to share this post at all.
    Thank you so much :-)




  • 0 comments:

    Post a Comment

    For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.