Chapter 4: Variables and Data Types
Chapter 4 of 15
Chapter 4: Variables and Data Types
4.1 Variables
Variables store data and are prefixed with $.
$name = "John";
$age = 30;
$price = 19.99;
$isActive = true;
4.2 Data Types
PHP supports various data types.
Scalar Types:
- String - Text data
- Integer - Whole numbers
- Float - Decimal numbers
- Boolean - true/false
Compound Types:
- Array - Ordered collection
- Object - Instance of a class
4.3 Type Casting
Convert between data types explicitly.
$number = (int) "123";
$string = (string) 123;
$float = (float) "3.14";