How many data type are present in PHP.

December 18, 2009 | Filed Under PHP | Comments Off

PHP supports 8  data  types.

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

Explaination:

4 scalar types:

boolean

<?php

$var = True; // assign the value TRUE to $foo
?>

integer

<?php
$var = 123; // decimal number
$var = -122; // a negative number
$var = 0111; // octal number
$var = 0x1B; // hexadecimal number

?>

float (floating-point number, aka double)

<?php
$var = 1.234;
$var= 1.2e3;
$var = 7E-10;
?>

string

<?php
$string =”Hello World”;  // Assign Hello World into $string

?>

2 compound types:

array

<?php
$array = array(“first”=>”Hello”,”second”=>”World”);

echo $array[‘first’];

echo $array[‘second];

?>

object

<?php

Class Interview

{

Function php()

{

Echo “What  is php”;

}

}

$obj = new Interview(); // $obj is object , you can also take different name   like  $object,$interview

Echo $obj-> php();

?>

3 compound types:

resource

NULL

<?php
$variable = NULL;
?>

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

Comments

Comments are closed.

© PHPInterviewQuestion.com 2009 - 2012

eXTReMe Tracker