PHP Data Types
PHP Data Types
PHP supports various data types, including integers, floats, strings, arrays, and objects. PHP variables can hold different types of data.
String: A sequence of characters enclosed in quotes.
E.g., $str = “Hello, World!”;
Integer: Whole numbers. E.g., $num = 42;
Float: Numbers with decimal points. E.g., $price = 19.99;
Boolean: Represents true or false. E.g., $isActive = true;
Array: A collection of values. E.g., $colors = array(“red”, “green”, “blue”);
Object: An instance of a class. E.g., $person = new Person();
NULL: A variable with no value. E.g., $var = NULL;
PHP is a dynamically typed language, meaning you don’t need to declare a variable’s type beforehand. The type is determined by the value assigned to it.
Example
<?php
// Integer data type
$age = 32;
// Float data type
$width = 5.9;
//String data type
$name = “John”;
//Boolean data typ
$is_active = true;
?>
PHP Tutorials
PHP Tutorials on this website:
More Information on PHP