PHP Examples

PHPOct 23, 2026

PHP aligned plain-text CLI table renderer

Renders headers and rows as an aligned plain-text table sized to the widest cell in each column.

formattingtablecli
000
PHPOct 23, 2026

PHP base64 encode and strict decode

Encodes binary strings as URL-safe base64 and decodes strictly, rejecting malformed input with an exception.

decodingencodingbase64
000
PHPOct 23, 2026

PHP build and parse query strings

Encodes arrays into RFC 3986 query strings and parses query strings back into PHP arrays.

query-stringurlhttp
000
PHPOct 23, 2026

PHP field-level input validation errors

Checks required, email, and integer rules per field, returning a map of field names to readable errors.

errorsvalidationforms
000
PHPOct 23, 2026

PHP JSON decode with actionable errors

Decodes JSON with exceptions that include the parser message and the start of the offending input.

parsingerrorsjson
000
PHPOct 23, 2026

PHP bounded round-robin worker pool

Distributes queued jobs across a fixed number of worker slots and returns each result or caught exception.

queueerrorsworkers
000
PHPOct 23, 2026

PHP HTTP GET JSON with stream timeout

Fetches a URL with a hard timeout, decodes its JSON body, and turns transport or parse failures into exceptions.

httpjsontimeout
000
PHPOct 23, 2026

PHP environment config with validation

Reads environment variables with defaults and regex validation, failing fast on missing or malformed values.

environmentconfigurationvalidation
000
PHPOct 23, 2026

PHP token bucket rate limiter

Allows short bursts up to the bucket size while enforcing a steady average request rate over time.

token-bucketthrottlingrate-limiting
000
PHPOct 23, 2026

PHP array-backed LRU cache with capacity

A fixed-capacity least-recently-used cache built on a PHP array evicts the oldest entry when full.

arrayslrucache
000
PHPOct 23, 2026

PHP split an iterable into fixed-size chunks

Splits any iterable into arrays of at most N items, yielding a final partial batch when input runs out.

batchinggeneratorsiterators
000
PHPOct 23, 2026

PHP multi-key stable sort with nulls last

Sorts records by multiple keys with direction control, keeping nulls last and preserving input order for ties.

sortingusortstable-sort
000
PHPOct 23, 2026

PHP stream a text file line by line

Yields each line of a text file without loading it into memory, closing the handle even on early exit.

generatorsstreamsfiles
000
PHPOct 23, 2026

PHP deep clone and recursive array merge

Recursively copies nested arrays and objects, then merges overrides without mutating the original structures.

arraysmergerecursionclone
000
PHPOct 23, 2026

PHP retry helper with capped exponential backoff

Runs a callable with capped exponential backoff and jitter, rethrowing the last error after the final attempt.

backoffretryjitter
000