Saturday , August 19 2017
Home / PHP / PHP Data types Example Tutorials

PHP Data types Example Tutorials

In this tutorials, I am going to give you the list of php data types. PHP data types are divided in about 8 categories. Here is the list..,

PHP data types :

  • Strings
  • Boolean
  • Float
  • Integer
  • Array
  • NULL
  • Resource

PHP String :

String is a stream of characters. They may be expressed in single or double quotes.


<?php
$v1="<p>Strings are expressed within double quotes</p>";
$v2='<p>Or single quotes as in this here</p>';

echo "<center><h1>PHP Strings</h1></center>";
echo $v1;
echo $v2;
?>

Output :

php data types 1

PHP Integer :

These are digits that span across the number line without decimals. PHP allows inputs of any digits between -2,147,483,648 and 2,147,483,647.

Integers must:

  1. Have at least a digit
  2. Have no decimals
  3. Be positive or negative
  4. Be stated in decimal, hexadecimal, or octal formats

<?php
$a=90273;
var_dump($a);
?>

The var_dump() function is used to display structured information (type and value) about one or more variables.

Output :

php data types 2PHP Float :

This statement parses numbers with decimal points and those with exponents.


<?php
$b = 3.14159;
var_dump($b);
?>

Output :

float(3.14159)

PHP Boolean

It is a variable that is often represented as bool. It is used in two states, which are to show whether the situation or outcome is TRUE or FALSE. It is used in conditional testing.

PHP Array

Arrays are variables that are used to store one or more (many) values. In the following example, the var_dump reveals an array.


<?php
$variables = array("Arrays","Boolean","integers");
var_dump($variables);
?>

Output :

array(3) { [0]=> string(6) “Arrays” [1]=> string(7) “Boolean” [2]=> string(8) “integers” }

PHP Object

It is a data type that stores instructions on how to process data. PHP objects must me declared explicitly, first under a class, which is a structure containing methods and properties.


<?php
class phones {
function phones() {
$this->company = "Apple";
}
}

// create an object
$model = new phones();

// show object properties
echo $model->company;
?>

Output :

Apple

PHP Null :

This data type returns only one value, which is NULL. It is returned if no value is assigned.

Values that are instantiated without value assignment are automatically given the NULL value. This data type may also be used to empty variables.


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

PHP Resource

It is a resource type that stores references to functions and external resources.

Happy Learning 🙂

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Recommended

PHP File Handling fopen fread and fclose Example

PHP has the File handling functionalities that allows us to make dynamic operations on files. …

Leave a Reply

Your email address will not be published. Required fields are marked *