PHP supports 8 data types.

  • boolean
  • integer
  • float (floating-point number, aka double)
  • string
  • array
  • object
  • resource
  • NULL

Explaination:

4 scalar types:

boolean

  1. <?php
  2. $var = True; // assign the value TRUE to $foo
  3. ?>

integer

  1. <?php
  2. $var = 123; // decimal number
  3. $var = -122; // a negative number
  4. $var = 0111; // octal number
  5. $var = 0x1B; // hexadecimal number
  6. ?>

float (floating-point number, aka double)

  1. <?php
  2. $var = 1.234;
  3. $var= 1.2e3;
  4. $var = 7E-10;
  5. ?>

string

  1. <?php
  2. $string =”Hello World”; // Assign Hello World into $string
  3. ?>

2 compound types:

array

  1. <?php
  2. $array = array(“first”=>”Hello”,”second”=>”World”);
  3. echo $array[‘first’];
  4. echo $array[‘second’];
  5. ?>

object

  1. <?php
  2. Class Interview
  3. {
  4. Function php()
  5. {
  6. Echo “What is php”;
  7. }
  8. }
  9. $obj = new Interview(); // $obj is object , you can also take different name like $object,$interview
  10. Echo $obj-> php();
  11. ?>

3 compound types:

resource

NULL

  1. <?php
  2. $variable = NULL;
  3. ?>

Note: PHP does not require to define variable in in any specific data type. Like integer,float,string etc, like C,C++.

PHP support automatic type conversion .
For More Detail see Type Juggling articles.

Thank you

eXTReMe Tracker