PHP Data Types
There are different data types for different purposes. PHP does not have explicit type definitions, but the type of a variable is determined by the type of the value that is assigned, or by the type that it is casted to. This is a brief overview about the types, for a detailed documentation and examples, see the PHP types topic.
There are following data types in PHP: null, boolean, integer, float, string, object, resource and array.
Null can be assigned to any variable. It represents a variable with no value.
This invalidates the variable and it's value would be undefined or void if called. The variable is cleared from memory and deleted by the garbage collector.
This is the simplest type with only two possible values.
Booleans can be used to control the flow of code.
An integer is a whole number positive or negative. It can be in used with any number base. The size of an integer is platform-dependent. PHP does not support unsigned integers.
Floating point numbers, "doubles" or simply called "floats" are decimal numbers.
An array is like a list of values. The simplest form of an array is indexed by integer, and ordered by the index, with the first element lying at index 0.
Arrays can also associate a key other than an integer index to a value. In PHP, all arrays are associative arrays behind the scenes, but when we refer to an 'associative array' distinctly, we usually mean one that contains one or more keys that aren't integers.
A string is like an array of characters.
Like an array, a string can be indexed to return its individual characters:
An object is an instance of a class. Its variables and methods can be accessed with the -> operator.
Resource variables hold special handles to opened files, database connections, streams, image canvas areas
To get the type of a variable as a string, use the gettype() function: