PHP automatics type conversion

PHP automatics type conversion

Automatic type conversion is essential when two differently typed variables are combined in an expression or when a variable is passed as an argument to a library function that expects a different type. In PHP when a variable of one type is used as another data type, it is automatically converted to a value of the required data type.

Example:
// $var is set as an integer = 115
$var = "100" + 15;
// $var is set as a float = 115.0
$var = "100" + 15.0;

PHP does not support explicit type definition in variable declaration; a variable's type is determined by the context in which the variable is used. For e.g. if $var is assigned a string value, the type of $var becomes string.
PHP arrays
Arrays are used for storing one or more values in a single variable name.
PHP operator
Operators are generally used to operate on values. Following are the types of operator’s used in PHP.
PHP class
PHP classes help to deal with data in an organized fashion.
Post your comment