What is data type in php definition?
PHP Data TypesVariables can store data of different types, and different data types can do different things. Show PHP supports the following data types:
PHP StringA string is a sequence of characters, like "Hello world!". A string can be any text inside quotes. You can use single or double quotes: Example$x = "Hello world!"; echo $x; Try it Yourself » PHP IntegerAn integer data type is a non-decimal number between -2,147,483,648 and 2,147,483,647. Rules for integers:
In the following example $x is an integer. The PHP var_dump() function returns the data type and value: PHP FloatA 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: PHP BooleanA Boolean represents two possible states: TRUE or FALSE. Booleans are often used in conditional testing. You will learn more about conditional testing in a later chapter of this tutorial. PHP ArrayAn array stores multiple values in one single variable. In the following example $cars is an array. The PHP var_dump() function returns the data type and value: Example$cars = array("Volvo","BMW","Toyota"); Try it Yourself » You will learn a lot more about arrays in later chapters of this tutorial. PHP ObjectClasses and objects are the two main aspects of object-oriented programming. A class is a template for objects, and an object is an instance of a class. When the individual objects are created, they inherit all the properties and behaviors from the class, but each object will have different values for the properties. Let's assume we have a class named Car. A Car can have properties like model, color, etc. We can define variables like $model, $color, and so on, to hold the values of these properties. When the individual objects (Volvo, BMW, Toyota, etc.) are created, they inherit all the properties and behaviors from the class, but each object will have different values for the properties. If you create a __construct() function, PHP will automatically call this function when you create an object from a class. Exampleclass Car { $myCar = new Car("black", "Volvo"); Try it Yourself » PHP NULL ValueNull is a special data type which can have only one value: NULL. A variable of data type NULL is a variable that has no value assigned to it. Tip: If a variable is created without a value, it is automatically assigned a value of NULL. Variables can also be emptied by setting the value to NULL: PHP ResourceThe special resource type is not an actual data type. It is the storing of a reference to functions and resources external to PHP. A common example of using the resource data type is a database call. We will not talk about the resource type here, since it is an advanced topic. In this tutorial you will learn about the data types available in PHP. Data Types in PHPThe values assigned to a PHP variable may be of different data types including simple string and numeric types to more complex data types like arrays and objects. PHP supports total eight primitive data types: Integer, Floating point number or Float, String, Booleans, Array, Object, resource and NULL. These data types are used to construct variables. Now let's discuss each one of them in detail. PHP IntegersIntegers are whole numbers, without a decimal point (..., -2, -1, 0, 1, 2, ...). Integers can be specified in decimal (base 10), hexadecimal (base 16 - prefixed with
Note: Since PHP 5.4+ you can also specify integers in binary (base 2) notation. To use binary notation precede the
number with 0b (e.g. PHP StringsStrings are sequences of characters, where every character is the same as a byte. A string can hold letters, numbers, and special characters and it can be as large as up to 2GB (2147483647 bytes maximum). The simplest way to specify a string is to enclose it in single quotes (e.g. 'Hello world!'), however you can also use double quotes ("Hello world!").
You will learn more about strings in PHP Strings tutorial. PHP Floating Point Numbers or DoublesFloating point numbers (also known as "floats", "doubles", or "real numbers") are decimal or fractional numbers, like demonstrated in the example below.
PHP BooleansBooleans are like a switch it has only two possible values either
PHP ArraysAn array is a variable that can hold more than one value at a time. It is useful to aggregate a series of related items together, for example a set of country or city names. An array is formally defined as an indexed collection of data values. Each index (also known as the key) of an array is unique and references a corresponding value.
You will learn more about arrays in PHP Array tutorial. PHP ObjectsAn object is a data type that not only allows storing data but also information on, how to process that data. An object is a specific instance of a class which serve as templates for objects. Objects are created based on this template via the new keyword. Every object has properties and methods corresponding to those of its parent class. Every object instance is completely independent, with its own properties and methods, and can thus be manipulated independently of other objects of the same class. Here's a simple example of a class definition followed by the object creation.
Tip: The data elements stored within an object are referred to as its properties and the information, or code which describing how to process the data is called the methods of the object. PHP NULLThe special NULL value is used to represent empty variables in PHP. A variable of type NULL is a variable without any data. NULL is the only possible value of type null.
When a variable is created without a value in PHP like PHP ResourcesA resource is a special variable, holding a reference to an external resource. Resource variables typically hold special handlers to opened files and database connections.
What is data type definition?A data type, in programming, is a classification that specifies which type of value a variable has and what type of mathematical, relational or logical operations can be applied to it without causing an error.
What is data type with example?A string data type is a combination of characters that can be either constant or variable. This often incorporates a sequence of character data types that result in specific commands depending on the programming language. Strings can include both upper and lowercase letters, numbers and punctuation.
|