Page 31 - Open Soource Technologies 304.indd
P. 31

Unit 2: Language Basics



            Variables in PHP consist of the $ character and a label. A label can be created from alphanumeric   Notes
            characters and an underscore (_) character. A variable cannot begin with a number. The PHP
            interpreter can then distinguish between a number and a variable more easily.
            $Value

            $value2
            $company_name
            These were valid identifiers.

            $12Val
            $exx$
            $first-name

            These were examples of invalid identifiers.
            The variables are case-sensitive. This means that $Price, $price, and $PRICE are three different
            identifiers.

            <?php
            $number = 10;
            $Number = 11;

            $NUMBER = 12;
            echo $number, $Number, $NUMBER;
            echo “\n”;

            ?>
            In our script, we assign three numeric values to three variables and print them.
            101112
            This is the output of the script.

            A Literal
            A literal is any notation for representing a value within the PHP source code. Technically, a literal
            will be assigned a value at compile time, while a variable will be assigned at runtime.
            $age = 29;
            $nationality = “Indian”;

            Here we assign two literals to variables. Number 29 and string Indian are literals.
            <?php
            $name1 = “Piyush “;

            $age1 = 25;
            $name2 = “Seema “;
            $age2 = 24;
            echo “Piyush 22\n”;
            echo “Rahul 22\n”;






                                             LOVELY PROFESSIONAL UNIVERSITY                                    25
   26   27   28   29   30   31   32   33   34   35   36