Data Type in PHP
What are PHP Data Types?
PHP Data Types define what type of data a variable can store in PHP programming. It tells the system whether the data is a number, text, decimal, true/false value
Why PHP Data Types are Important?
✔ They help organize data correctly
✔ Improve code readability
✔ Help in calculations and logic
✔ Prevent errors in programming
✔ Make data handling easy and efficient
Types Of PHP Data Types With Examples
Represents a sequence of characters.
Example: $name = "seeta";
PHP Integer :-
Represents whole numbers without decimal points.
Example :- $number = 100;
PHP Float :-
Floating point numbers or Doubles
Represents numbers with decimal points.
Example :- $float_number = 9.7;
PHP Boolean :-
Represents true or false values.
Example: true;
PHP Array :-
Represents a collection of elements, each identified by a key.
Example: $colors = array("red", "green", "blue");
PHP Object :-
Represents instances of user-defined classes.
Example:
class Car { public $color = "blue"; public $make = "Toyota"; } $car = new Car();
PHP NULL :-
$variable = null;- PHP Resource :-
- Represents a special variable that holds a reference to an external resource.
- A common example of using the resource data type is a database call. It is the storing of a reference to functions and resources external to PHP.
Type of PHP Data :-
1] integer ➡ Whole Number
- </> PHP $number = 10;
2] float ➡ Decimal Number
</> PHP $price=10.7;
3] string ➡ Text Data
</> PHP
$name ="PHP";
4] boolean ➡ True or False
</> PHP $isActive = true;
5] array ➡ Multiple Value
</> PHP $colors = array("Blue","yellow","green");
6] object ➡ Stores Data
</> PHP
class Car { public $name;}
$car = new Car();$car->name = "BMW";echo $car->name;
7] Null ➡ No Value
</> PHP $date = null
2] float ➡ Decimal Number
3] string ➡ Text Data
4] boolean ➡ True or False
5] array ➡ Multiple Value
6] object ➡ Stores Data
7] Null ➡ No Value
- Understand PHP Data Types Like a Pro (Beginner to Advanced)
- PHP data type Code
- PHP data typeOutput

No comments:
Post a Comment