Data Types in Php
PHP supports the following data types:
- String (Ex- Techalltype)
- Integer (Ex- 786)
- Float (Ex- 786.50)
- Boolean (Ex- True, False)
Php as String :-
A string is basically collection of characters, which make meaningful sense, in php string strings are defined in quotes. Lets see with an example:-
$x = “Hello Techalltype”;
$tech = ‘Hello Techalltype’;
echo $tech ;
Hello Techalltype // display value of string stored in $x variable.
Hello Techalltype // display value of string stored in $tech variable.
General rules for declaring String:-
- Use of Alphabets (Ex – techalltype).
- Alphabets Number Alphabets (Ex- tech123alltype).
- Alphabets underscore Alphabets (Ex- Tech_alltype).
- Underscore Alphabets (Ex- _techalltype).
- Not start with Numbers (Ex- 123techalltype).
Php as Integer :-
Lets show with an example :-
$x = 786;
var_dump($x); // var_dump function is used to know variable types here it is an integer
Basic of Integer
- In general terms integer are the numbers.
- It should be minimum 1 in numbers.
- Doesn’t include any alphabets.
- Numbers can be positive or negative
Important points related to Integer and string
- Generally php understand that the variable values assigned in single/double quotes is a string. (Ex – $tech= “Tech all Type”;).
- Integer values are assigned without any quotes. (Ex- $techalltype = 100;).
Note:- If any integer is assigned in quotes(Single/Double) php understand as string, and if any string is assignd without quotes(Single/Double) it will act as integer.
- Php as Float:-
Float is just like integer with decimal point.
Lets see with an example.
$x = 786.123;
var_dump($x); // var_dump function is used to know variable types here it is an Float because it consist of decimal point
Php as Boolean:-
A Boolean used to check possible states: TRUE or FALSE. It is used in testing condition.
Let’s see with an example:-
$x = true;