coderef

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.

  • PHP block
  • Variables
  • Output
  • Null coalescing
  • Type check / convert

Strings

Text functions.

  • Interpolation
  • Concatenate
  • Length / case
  • Contains / starts with
  • Replace / trim
  • Split / join
  • Format
  • Escape for HTML

Arrays

Lists and maps.

  • Indexed array
  • Associative array
  • Loop
  • Count / exists
  • Map / filter / reduce
  • Sort
  • Reverse
  • Merge / keys / values
  • Destructure

Control flow & functions

Logic and reuse.

  • If / else
  • Match
  • Loops
  • Typed function
  • Default / named arguments
  • Arrow function

Classes

Object-oriented PHP.

  • Class with constructor promotion
  • Create / use
  • Inheritance / interface
  • Static
  • Enum
  • Readonly property

Files, JSON & web

Common tasks.

  • Read / write a file
  • JSON
  • Request data
  • Sessions
  • Redirect
  • Hash a password
  • Try / catch
  • Built-in server

← All quick references