PHP Tutorial - Variables & Data Types
๐ฆ Variables Aur Data Types
๐ Container Analogy:
๐ฆ Variable = Dabba (storage)
๐ท๏ธ $ sign = PHP ka symbol
๐ Value = Dabba mein rakha data
Example: $age = 25;
๐ Variable Rules
- Start with $ (dollar sign)
- Letter or underscore after $
- Case-sensitive ($age โ $Age)
- No spaces allowed
๐ Data Types
| Type | Example | Use |
|---|---|---|
| String | "Hello", 'World' | Text |
| Integer | 25, -10 | Whole numbers |
| Float | 3.14, 25.5 | Decimals |
| Boolean | true, false | Yes/No |
| Array | ["a", "b"] | Lists |
| NULL | null | Empty |
๐ฏ Variable Scope
3 Types
// Local - function ke andar
function test() {
$local = "inside";
}
// Global - bahar
$global = "outside";
// Static - value retain
static $count = 0;
Example
<?php
$name = "Rohan";
$age = 25;
$height = 5.8;
?>