[Part 3] Constants! Oh noes!

Iamcoolz Feb 17, 2015

  1. Iamcoolz

    Iamcoolz Forum Administrator Staff Member XPG Administrator
    205/282

    Joined:
    Mar 30, 2012
    Messages:
    1,227
    Likes Received:
    507
    Trophy Points:
    205
    Gender:
    Male
    Location:
    XPG
    Console:
    Xbox One
    What is it?
    A constant, just as everyone know's the definition of a constant, it is something that doesn't change. A constant in PHP is basically the same thing, it is a value that cannot change during a script being ran. Like most PHP functions, there are specific ways they need to be wrote and outlined in your code. A constant are always uppercase, why? No one knows, it just looks cleaner. Once you define a constant or set one into place, it can not be changed.

    Defining a constant?
    Defining a constant is easy as typing define() and putting your variables inside and what you wish to define or set.

    The constant function:
    When you type in a definition of a constant, you may have several hundreds, therefore it becomes hard to remember what you set. So, luckily, you can use the same command we used in the beginning in our introduction "echo"

    Example -

    <?php

    define('HEIGHT', 75);

    echo HEIGHT;
    ?>
    It's a beautiful function, and I use it quite frequently.

    -Iamcoolz
     

Share This Page

Close