|
|
|---|
Data Types in PHPIn PHP a variable can hold data of any type. These data types are as following:
Assigning data typesUnlike other programming languages, PHP does not require formal declaration of the data type of a variable. When you assign certain value to a variable, PHP will automatically try to guess the type of data being stored and assign the data type to the variable. When needed PHP will automatically convert the data type.
<?Here data type of $a is automatically converted to a real number and then added with the value of $b which is a real number too. Type CastingSometimes, there might be a need to change the data type of a certain variable from string to an integer and then back to a string. Such manual over riding of data types is called Type Casting. Since PHP will automatically change the data type, chances are rare that you will need to use type casting at all. To specify a different of a particular data type, use the following:
<?Determining Data TypeTo find out the data type of a variable, use a statement like the following:
<?This will output the data type and value of the variable. In this case, the output will be int(100) |
|
|
|---|