You don't need to declare a type when creating a variable—PHP figures it out automatically:
$x = 5; // Integer
$y = "Hello"; // String
$z = 3.14; // FloatText enclosed in quotes:
$text = "PHP is fun";Whole numbers:
$num = 100;Decimal numbers:
$pi = 3.14159;Either true or false:
$isLoggedIn = true;Stores multiple values:
$fruits = array("apple", "banana", "cherry");Instance of a class:
class Car {
public $brand;
}
$myCar = new Car();
$myCar->brand = "Toyota";Represents a variable with no value:
$data = null;Special type used for file and database connections. Example:
$handle = fopen("test.txt", "r");Use var_dump() to display type and value:
$x = "PHP";
var_dump($x);is_string()is_int()is_float()is_bool()is_array()is_object()if (is_array($fruits)) {
echo "This is an array.";
}Ask the AI if you need help understanding or want to dive deeper in any topic