What is DataType in php?

PHP data types define what types of data used in your application. and what types of data used in appliaction.

Each variable contain a specific data type.

PHP Support 8 types of datatypes.

  • Integer
  • Float
  • String
  • Boolean
  • Array
  • Object
  • Resource
  • NULL
  • Scalar Types :- There are 4 scalar data types in PHP. It holds only single value.

  • Integer
  • Float
  • Boolean
  • String
  • user-defined :- There are 2 user-define data types in PHP. It holds multiple value.

  • Array
  • Object
  • Special Types :- Two Special datatype in PHP.

  • Resource
  • NULL
  • Integer Data Type :-

    Integer data type contain numeric value (negative or positive) . integer data type store only numeric numbers, i.e., numbers without fractional part or decimal points.

    Integer creation Rules :-

  • An integer can be either positive or negative.
  • An integer must have at least one digit
  • An integer must not contain decimal point.
  • Integers can be specified in: decimal (base 10), hexadecimal (base 16), octal (base 8), or binary (base 2) notation
  • An integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647
  • Integer Data Type Example :-

    File Name :

    $water_temp = 98;
    $ice_temp = -2;
    $decimal_no = 84;
    $octal = 0284;
    $hexadecimal = 0x32;
    echo "water temperature: " .$water_temp. "
    ";
    echo "Ice temperature: " .$ice_temp. "
    ";
    echo "Decimal number: " .$decimal_no. "
    ";
    echo "Octal number: " .$octal. "
    ";
    echo "HexaDecimal number: " .$hexadecimal. "
    ";
    ?>

    Output :-

    water temperature : 98
    Ice Temperature : -2
    Decimal number : 84
    Octal number : 434
    HexaDecimal Number : 32

    Float Data Type

    A Floatin-ponit number is a number which contain decimal point. it hold numbers with a fractional or decimal point, including a negative or positive sign.

    File Name : index.php

    <?php
    $n1 = 2.4;
    $n2 = 7.6;
    $sum = $n1 + $n2;
    echo "Total : " .$sum;
    ?>

    Output :-

    Total : 10.0





    Previous Next


    Trending Tutorials




    Review & Rating

    0.0 / 5

    0 Review

    5
    (0)

    4
    (0)

    3
    (0)

    2
    (0)

    1
    (0)

    Write Review Here