PHP 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.
  • decimal: a base ten numbering system.
  • Integers can be written in decimal, octal, or hexadecimal. 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

    +7

    -1007395

    Valid octal integers:
    01

    0123

    +07

    -01007345

    Valid hexadecimal integers:
    0x1

    0xff

    0x1a3

    +0x7
    -0x1ab7345


    Example : The PHP var_dump() function returns the data type and value of variables:

    <?php
    $a = 5;
    var_dump($x);
    echo "<br>";
    $x = -5;                                   // negative number
    var_dump($x);
    echo "<br>";
    $x = 0x8C;                            // hexadecimal number
    var_dump($x);
    echo "<br>";
    $x = 047;                              // octal number
    var_dump($x);
    ?> 




Comments