.png)
PHP Information Types
Variables can store information of diverse sorts, and diverse information sorts can do diverse things.
PHP bolsters the taking after information types:
- String
- Integer
- Float (coasting point numbers - moreover called double)
- Boolean
- Array
- Object
- NULL
- Resource
- Getting the Information Type
You can get the information sort of any protest by utilizing the var_dump() function.
Exmple:
PHP String
A string is a grouping of characters, like "Hi world!".
A string can be any content interior cites. You can utilize single or twofold quotes:
Example:
PHP Integer
An numbers information sort is a non-decimal number between -2,147,483,648 and 2,147,483,647.
Rules for integers:
An numbers must have at slightest one digit
An numbers must not have a decimal point
An numbers can be either positive or negative
Integers can be indicated in: decimal (base 10), hexadecimal (base 16), octal (base 8), or parallel (base 2) notation
In the taking after case $x is an numbers. The PHP var_dump() work returns the information sort and value:
Example:
PHP Float
A drift (drifting point number) is a number with a decimal point or a number in exponential form.
In the taking after case $x is a coast. The PHP var_dump() work returns the information sort and value:
Example:
PHP Boolean
A Boolean speaks to two conceivable states: Genuine or FALSE.
Example
PHP Array
An cluster stores different values in one single variable.
In the taking after case $cars is an cluster. The PHP var_dump() work returns the information sort and value:
Example:
PHP Object
Classes and objects are the two primary viewpoints of object-oriented programming.
A course is a layout for objects, and an protest is an occasion of a class.
When the person objects are made, they acquire all the properties and behaviors from the lesson, but each question will have distinctive values for the properties.
Let's expect we have a course named Car that can have properties like demonstrate, color, etc. We can characterize factors like $show, $color, and so on, to hold the values of these properties.
When the person objects (Volvo, BMW, Toyota, etc.) are made, they acquire all the properties and behaviors from the lesson, but each protest will have diverse values for the properties.
If you make a __build() work, PHP will consequently call this work when you make an question from a class.
Example:
PHP Invalid Value
Null is a uncommon information sort which can have as it were one esteem: NULL.
A variable of information sort Invalid is a variable that has no esteem doled out to it.
Tip: If a variable is made without a esteem, it is naturally alloted a esteem of NULL.
Variables can too be purged by setting the esteem to NULL:
Example:
Change Information Type
If you relegate an numbers esteem to a variable, the sort will naturally be an integer.
If you dole out a string to the same variable, the sort will alter to a string:
Example:
Please see my previous tutorials ...
Part 1 Link
Part 2 Link
Part 3 Link