PHP Date Type

Variables can store or hold data of different types such as String, Integer, Float or double, Boolean, Array.

  • a. String is a sequence of characters or any text inside single or double quotes

    String Example

    <?php
    $name="Ben Onuorah";
    $msg="Welcome to my site";
    print "$name <br/> $msg";
    ?>

  • b. Integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647.

    Integer Example

    <?php
    $price=15000;
    ?>

  • c. Float is a number with a decimal point or in exponential form.

    Float Example

    <?php
    $discount=50.5;
    ?>

  • d. Boolean represents two (true or false) states. e.g $married=true;

    Boolean Example

    <?php
    $married=true;
    ?>

  • e. Array stores multiple values in one variable.

    Array Example

    <?php
    $ng_states = array("Anambra","Edo","Kaduna","Lagos");
    ?>

    • Using var_dump() to know the data type

      var_dump() Example

      <?php
      //array holding student name, age, height, married
      $student = array(“Ben”, 35, 5.6, true);
      //var_dump() function returns data type and value
      var_dump($student);
      ?>


      Next »


Home    |    Learn Programming   |    Learning Management System   |    Computer Based Testing System    |    Contact Us