PHP Data Types

Posted on Updated on

hjghjPHP Data Types

Variables store data of different types, and different data types can do different things.

PHP supports the following data types:

  • String
  • Integer
  • Float (floating point numbers – also called double)
  • Boolean
  • Array
  • NULL
  • Resource

 

 PHP String

A string is a sequence of characters, like “Hello world!”.

exp

<?php
$x = “Hello world!”;
$y = ‘Hello world!’;

echo $x;
echo “<br>”;
echo $y;
?>

 PHP Integer

It is a number between -2,147,483,648 and +2,147,483,647.

Rules for integers:

  • An integer must have at least one digit (0-9)
  • An integer can’t contain comma, blanks
  • An integer can’t contain decimal point
  • An integer may positive or negative
  • Integers can be specified in three formats: decimal (10-based), hexadecimal (16-based – prefixed with 0x) or octal (8-based – prefixed with 0)

In the following example $abc is an integer variable.The PHP var_dump() function is use to  display the data type and value:

Exp:

<?php
$abc = 5983;
var_dump($abc);
?>

 PHP Float

A float (floating point number) is a number with a decimal point or a number in exponential form.

In the following example $x is a float. The PHP var_dump() function returns the data type and value:

Exp:

<?php
$x = 10.365;
var_dump($x);
?>

 PHP Boolean

Boolean return only two values true or false.

$x = true;
$y = false;

Boolean is use for conditions.

PHP Array

An array is collection of same data type values.

In the following example $abc is an array. The PHP var_dump() function returns the data type and value:

exp:

<?php
$abc = array(“a”,”b”,”c”);
var_dump($abc);
?>

 PHP NULL Value

Null is use for special purpose its have only one value NULL. we can’t assignee any value to it.

Tip: If a variable havn’t  a value, it is automatically assigned a value of NULL.

Variables can also be emptied by setting the value to NULL:

Exp:

<?php
$x = “Hello world!”;
$x = null;
var_dump($x);
?>

 For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.

Helpline: 9814666333, 8699444666

Email:info@technocampus.co.in

**************************************************************************************************************

Please fill the FORM and we shall contact you soon.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s