Variables and Types
Create variables
Variable names start with $ and are case-sensitive.
<?php
$title = "PHP";
$lessons = 18;
$ready = true;
echo $title, " ", $lessons, "\n";
Inspect types
PHP is dynamically typed. Use helpers while learning.
var_dump($title);
var_dump($lessons);
echo gettype($ready), "\n";
Null and unset
null means no value. unset removes a variable.
$value = null;
var_dump(is_null($value));
Type tips
- Common types: string, int, float, bool, array, object, null
- Loose comparisons with
==coerce types; prefer=== - Type declarations on functions improve clarity in modern PHP
- Prefixes like
is_helpers check types at runtime
Comments
One comment per signed-in account. Comments are saved with this page’s URL.