PHP Quick Reference
PHP essentials: variables, strings, arrays, control flow, functions, classes, files, JSON and superglobals.
6 sections · 42 snippets · updated Oct 14, 2026
Click any snippet to copy it.
Basics
Variables and output.
TaskCode
- PHP block
- Variables
- Output
- Null coalescing
- Type check / convert
Strings
Text functions.
TaskCode
- Interpolation
- Concatenate
- Length / case
- Contains / starts with
- Replace / trim
- Split / join
- Format
- Escape for HTML
Arrays
Lists and maps.
TaskCode
- Indexed array
- Associative array
- Loop
- Count / exists
- Map / filter / reduce
- Sort
- Reverse
- Merge / keys / values
- Destructure
Control flow & functions
Logic and reuse.
TaskCode
- If / else
- Match
- Loops
- Typed function
- Default / named arguments
- Arrow function
Classes
Object-oriented PHP.
TaskCode
- Class with constructor promotion
- Create / use
- Inheritance / interface
- Static
- Enum
- Readonly property
Files, JSON & web
Common tasks.
TaskCode
- Read / write a file
- JSON
- Request data
- Sessions
- Redirect
- Hash a password
- Try / catch
- Built-in server