Tutti gli strumenti
Gratuito

Un riferimento ricercabile e stampabile di PHP 8.3+ — sintassi, stringhe, array, funzioni, classi, enum, attributi e funzionalità moderne. Gratis.

Basics & types

10
declare(strict_types=1);
Enforce strict scalar type checks
$x = 1;
Variables start with a dollar sign
const MAX = 100;
Compile-time constant
gettype($x)
Get the type of a value
(int) $x
Cast to an integer
is_int($x)
Type-check helper (is_string, ...)
int|string $x
Union type declaration
?string $x
Nullable type (string or null)
$a ?? 'default'
Null coalescing operator
$a ??= 'default'
Assign only if null

Strings

11
"Hello $name"
Double quotes interpolate variables
'literal $x'
Single quotes are literal
$a . $b
Concatenate strings
strlen($s)
Byte length of a string
str_contains($s, 'a')
Check for a substring
str_starts_with($s, 'a')
Check the prefix
substr($s, 0, 3)
Extract part of a string
str_replace('a', 'b', $s)
Replace all occurrences
explode(',', $s)
Split into an array
sprintf('%05.2f', $n)
Formatted string output
trim($s)
Strip surrounding whitespace

Arrays

11
$a = [1, 2, 3];
Indexed array literal
$a = ['k' => 'v'];
Associative array
array_map(fn($x) => $x * 2, $a)
Transform each element
array_filter($a, fn($x) => $x > 0)
Keep matching elements
array_reduce($a, $fn, 0)
Reduce to a single value
in_array($v, $a, true)
Strict value check
array_keys($a)
Get all keys
array_merge($a, $b)
Merge arrays
[...$a, ...$b]
Spread/merge arrays
count($a)
Number of elements
[$x, $y] = $a;
Array destructuring

Functions

9
function f(int $a): int {}
Typed parameters and return
function f(int $a = 1) {}
Default parameter value
function f(int ...$nums) {}
Variadic parameters
f(...$args)
Spread arguments
f(name: 'Sam', age: 30)
Named arguments
$fn = fn($x) => $x + 1;
Arrow function (auto-captures scope)
function () use ($x) {}
Closure capturing a variable
$fn = strlen(...);
First-class callable syntax
function f(): never {}
Never returns (throws or exits)

Control flow

9
if ($a) {} elseif ($b) {} else {}
Conditional branches
$a ? $b : $c
Ternary expression
$a ?: $b
Short ternary (falsy fallback)
match ($x) { 1, 2 => 'a', default => 'b' }
Strict, expression-based match
switch ($x) { case 1: break; }
Loose multi-way branch
foreach ($a as $k => $v) {}
Iterate keys and values
for ($i = 0; $i < 10; $i++) {}
Counted loop
while ($cond) {}
Loop while a condition holds
break / continue
Exit or skip a loop iteration

Classes & OOP

10
class A extends B implements C {}
Inheritance and interfaces
public function __construct(private int $id) {}
Constructor property promotion
public readonly string $name;
Immutable after initialization
public function f(): static {}
Return the late-bound type
static::create()
Late static binding
$obj?->method()
Null-safe method call
abstract class A {}
Cannot be instantiated directly
trait T {} use T;
Reusable horizontal code
$obj instanceof A
Type check at runtime
A::class
Fully-qualified class name string

Enums

9
enum Status { case Active; case Draft; }
Pure enumeration
enum Status: string { case A = 'a'; }
Backed enum (string/int)
Status::Active
Reference an enum case
Status::from('a')
Build from a backing value
Status::tryFrom('x')
Returns null if invalid
Status::cases()
Array of all cases
$status->value
Backing value of a case
$status->name
Name of the case
enum E { public function label() {} }
Enums can have methods

Error handling

9
try {} catch (Throwable $e) {}
Catch errors and exceptions
catch (TypeError | ValueError $e)
Catch multiple types
catch (Exception)
Non-capturing catch (no variable)
finally {}
Always runs after try/catch
throw new RuntimeException('x')
Throw an exception
throw $e;
Re-throw the caught exception
$x = $v ?? throw new Error();
Throw as an expression
$e->getMessage()
Read the error message
$e->getPrevious()
Get the chained exception

Attributes & modern

9
#[Attribute] class Route {}
Declare a custom attribute
#[Route('/home')]
Apply an attribute to a target
new ReflectionClass($x)
Inspect a class via reflection
$ref->getAttributes()
Read declared attributes
json_encode($data)
Serialize to JSON
json_decode($s, true)
Decode JSON to an array
array_is_list($a)
True if keys are 0..n in order
str_word_count($s)
Count words in a string
$obj::class
Class name from an instance

Nessuna voce corrisponde a “:q”.


Informazioni su Scheda di Riferimento PHP

Questo prontuario PHP condensa il PHP moderno in una pagina ricercabile: basi e tipi, stringhe, array, funzioni, controllo di flusso, classi e OOP, enum, gestione degli errori, e attributi e altre funzionalità moderne. Ogni riga è uno snippet eseguibile con una descrizione in linguaggio semplice.

È mirato a PHP 8.3+, quindi troverai le funzionalità che definiscono il PHP attuale: enum, proprietà readonly, promozione delle proprietà nel costruttore, argomenti nominati, espressioni match, arrow function, chiamate nullsafe e attributi, accanto alle funzioni per stringhe e array di uso quotidiano.

La pagina è gratuita e interamente lato client: la ricerca filtra le righe mentre digiti, il menu di sezione fisso ti fa saltare in giro nel prontuario, un clic copia qualsiasi snippet, e un pulsante di stampa lo trasforma in un riferimento PHP su carta.

Come usare Scheda di Riferimento PHP

  1. Scorri il sommario, da Basi e tipi a Enum, Gestione degli errori e Attributi e moderno.
  2. Digita il nome di una funzione o una parola chiave nella casella di ricerca per filtrare istantaneamente l'intero prontuario.
  3. Salta a una sezione come Classi e OOP tramite la barra laterale di navigazione fissa.
  4. Clicca qualsiasi snippet o la sua icona di copia per copiare il codice PHP negli appunti.
  5. Premi Stampa se vuoi l'intero riferimento su carta.

Domande frequenti

È scritto per PHP 8.3 e versioni successive. Le sezioni su enum, attributi e funzionalità moderne coprono proprietà readonly, promozione nel costruttore, espressioni match, argomenti nominati e chiamate nullsafe oltre alla sintassi classica.

Nove sezioni: basi e tipi, stringhe, array, funzioni, controllo di flusso, classi e OOP, enum, gestione degli errori, e attributi più funzionalità moderne: le parti di PHP che usi quotidianamente nei progetti reali.

Usa la casella di ricerca in alto. Filtra ogni riga dal vivo in tutte le sezioni e mostra un conteggio dei risultati, così digitando qualcosa come array_map il prontuario si riduce istantaneamente agli snippet pertinenti.

Sì. Clicca il codice stesso o l'icona di copia al passaggio del mouse e lo snippet finisce negli appunti, confermato da un breve lampeggio "Copiato!".

Sì, interamente gratuito. Si carica nel tuo browser, non richiede account e può essere stampato tutte le volte che vuoi.


Ricerche popolari
php cheat sheet php syntax reference php array functions php string functions php enums example php 8 attributes php oop cheat sheet php try catch example
Hai bisogno di aiuto?
Hai riscontrato un problema con questo strumento? Faccelo sapere.
Segnala un problema

Aggiungi questo strumento gratuito al tuo sito web — copia e incolla il codice qui sotto.