R
Rishtaara
PHP Fundamentals
Lesson 4 of 32Article17 min

Data Types, Strings & Numbers

PHP supports string, integer, float, boolean, array, object, NULL, and resource types. Variables are loosely typed — type can change on reassignment.

Data Types

PHP supports string, integer, float, boolean, array, object, NULL, and resource types. Variables are loosely typed — type can change on reassignment.

Real-life example: Data types are container shapes — a string holds words, an integer holds whole counts, a float holds prices with decimals.

Common data types
<?php
$text = "Rishtaara";     // string
$count = 32;            // integer
$rating = 4.8;          // float
$active = true;         // boolean
$empty = null;          // NULL

var_dump($text, $count, $rating, $active, $empty);
?>

Strings

Use single quotes for plain text and double quotes when you need variable interpolation or escape sequences like \n.

Real-life example: Single quotes are a plain white T-shirt. Double quotes are a T-shirt with your name printed on it.

String quotes and concatenation
<?php
$first = "Asha";
$last = "Khan";

// Concatenation with .
$full = $first . " " . $last;

// Double quotes interpolate variables
echo "Hello, $full";

// Useful string functions
echo strlen($full);       // length
echo strtoupper($first);  // ASHA
?>

Numbers — Integers and Floats

Integers are whole numbers. Floats (doubles) have decimal points. PHP automatically picks the type from how you write the value.

Real-life example: Integers count whole apples. Floats measure weight when you need grams and decimals.

Integer and float operations
<?php
$lessons = 32;
$hours = 10.5;
$totalMinutes = $lessons * 30 + $hours * 60;

echo "Total study minutes: $totalMinutes";
echo is_int($lessons) ? " lessons is int" : "";
echo is_float($hours) ? " hours is float" : "";
?>