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

Web Technologies-I



                   Notes
                                    •  Strings
                                    •  Booleans
                                    •  Arrays
                                    •  Objects
                                    •  Resouces
                                    •  Null
                                 The data types in order to be able to work with the language.

                                 2.2.1 Integers
                                 An integer is a whole number. That is to say, it is a number with no fractional component. For
                                 those who are familiar with C, a PHP integer is the same as the long data type in C. It is a number
                                 between –2,147,483,648 and +2,147,483,647.

                                 Integers can be written in decimal, octal, or hexadecimal forms. Decimal numbers are a string of
                                 digits with no leading zeros. Any integer may begin with a plus sign (+) or a minus sign (–) to
                                 indicate whether it is a positive or negative number. If there is no sign, then positive is assumed.
                                 Valid decimal integers:

                                 1
                                 123
                                 +07
                                 -01007345

                                 An octal number is a base-8 number. Each digit can have a value between zero (0) and seven (7).
                                 Octal numbers are commonly used in computing because a three digit binary number can be
                                 represented as a one digit octal number. Octal numbers are preceded by a leading zero (e.g., 0123).
                                 Valid octal integers:
                                 01

                                 0123
                                 +07
                                 –01007345

                                 A hexadecimal number is a base-16 number. Each digit can have a value between zero (0) and F. Since
                                 we only have ten numbers in our numbering system (0-9), we use the letters A through F to make
                                 up the difference for hexadecimal values. Hexadecimal values are common in computing because
                                 each digit represents 4 binary numbers, which is four bits, eight bits, or a two digit hexadecimal
                                 number, is one byte. Hexadecimal numbers are preceded by a leading zero and X (e.g. 0x123).
                                 So what about zero, you may ask. If anything beginning with a zero is octal then is non zero octal?
                                 And how do we represent a decimal zero then? The answer is simple. It makes no difference. If
                                 you have zero of something, it does not matter how you count it, it is still zero.

                                 If you want to find out whether a variable stores an integer you can use the is_integer() function
                                 (is_int() for short) to test whether something is an integer. If it is, then the function returns the
                                 value of true.
                                                PHP is a loosely-typed language, so a variable does not need to be of a specific
                                                type and can freely move between types as demanded by the code it is being
                                                used.


        28                                LOVELY PROFESSIONAL UNIVERSITY
   29   30   31   32   33   34   35   36   37   38   39