A PHP cheat sheet for 2026 assumes PHP 8+: typed properties, match, the nullsafe operator, named arguments, and PDO for SQL. PHP still renders HTML, talks to MySQL, and runs on Apache/XAMPP. Skip mysql_* functions, unquoted array keys, and mixing HTML with SQL.
This PHP cheat sheet is written for people searching for a fast, accurate reference: students, junior developers, and teams shipping production software. Pin it, copy the snippets, and come back when syntax slips.
Quick reference
- Tags:
<?phpstart. Echo short<?= $title ?>in views. Skip<?short open if it is disabled. - Types:
string,int,float,bool,array,object,mixed,?stringnullable. - Arrays:
[1, 2]and["k" => "v"].foreach ($rows as $k => $v). - Functions:
function add(int $a, int $b): int { return $a + $b; }. - Nullsafe:
$user?->email— no notice if$useris null. - match:
match ($status) { "ok" => 1, default => 0 }— strict compare. - String: Double-quoted strings interpolate
$name. Use heredoc/nowdoc for long SQL or HTML blocks. - Errors: Throw
Exception. Do not@suppress.declare(strict_types=1);in new files.
Copy-paste examples
Typed helper and match
Enable strict types in new files. match is not switch — it returns a value and uses ===.
<?php
declare(strict_types=1);
function label(?string $status): string
{
return match ($status) {
'paid' => 'Paid',
'due' => 'Due',
null, '' => 'Unknown',
default => 'Other',
};
}
function firstEmail(array $user): ?string
{
return $user['email'] ?? $user['contact']['email'] ?? null;
}Common mistakes
- Using
mysql_queryor concatenated SQL from$_GET. ==with"0"andfalsein auth checks — use===andhash_equalsfor secrets.- Outputting user HTML without
htmlspecialchars. - Editing files without
declare(strict_types=1)then passing"1"as int everywhere.
FAQ
- Is PHP dead? No. WordPress, Laravel, and a huge web install base still run PHP 8. Treat it as a modern language, not PHP 4 tutorials.
- PHP vs Laravel? Laravel is a framework on PHP. Learn PHP arrays, PDO, and requests first, then Blade and routing.
- How do I run this on XAMPP? Put the project under
htdocs, start Apache (and MySQL if needed), openhttp://localhost/....
Related PHP cheat sheets
Build with this stack
When a cheat sheet is not enough — you need a production app, a student FYP, or a custom dashboard — ArpaNeuro builds custom web development and also sells ready-made source code. Request a quote and tell us the stack.
Browse software development services or the source code marketplace if you want a working codebase instead of starting from a blank file.