Data Types in PHP

In this tutorial we will learn about Data Types in PHP. PHP support various data types like strings, numeric types complex data types like array and objects. There are total eight data types available in PHP that are integer, float, string, boolean, array, object, resource and NULL. These data types are use to define what kind of data a variable can store.

Data Types in PHP


Now we will learn every data type in detail with the help of examples.

Integer: In integer data type we can store integers mean decimal numbers, octal numbers, and hexadecimal numbers. These number may be signed or unsigned depends on requirements means like 10 or +10;

Example

";
 
$num2 = -123; // signed integer
echo $num2;
echo "
"; $num3 = 0x1A; // hexadecimal number echo $num3; echo "
"; $num4 = 0123; // octal number echo $num4; ?>


Float: Using this data type we can store decimal values like 2.5 or 3.2555 etc

Example

";
?>



String: In strings data type we can store sequence of characters, special symbols or numbers. To store any value in string type value must be enclosed in single or double quotes like 'Owlbuddy' or "Owlbuddy".

Example

";
 
$str2 = "Owlbuddy";
echo $str2;
echo "
"; ?>


Boolean: Boolean can hold only two values which are true or false. You can not store any other value in boolean type. Boolean are so helpful while working with conditional statements.

Example





Array: Array can be use to store collection of similar kind of data in single variable. Suppose you want to store age of 10 students you can easily do this using Array.

Example





Object: Object allow us to store different kind of data at once for example you created object called Chair. In this object Chair you can save data like chair_height, chair_Price, chair_color. Apart from saving data in Object you also mention relation functions in object.

Example

$name;
    }
}
 
// Create object from class
$car1 = new car;
?>



Resource: This type of variables are use to hold reference of external resource.

Example

";
?>



Null: This data tye is used to represent any empty variable.

Example

";





Share this tutorial with your friends on your social Media..

Data Types in PHP Data Types in PHP Data Types in PHP Data Types in PHP



Now You Can Follow All These Tutorials on Your Android Mobile Just Download This App.


Owlbuddy.com