PHP Examples
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.
PHP base64 encode and strict decode
Encodes binary strings as URL-safe base64 and decodes strictly, rejecting malformed input with an exception.
PHP build and parse query strings
Encodes arrays into RFC 3986 query strings and parses query strings back into PHP arrays.
PHP field-level input validation errors
Checks required, email, and integer rules per field, returning a map of field names to readable errors.
PHP JSON decode with actionable errors
Decodes JSON with exceptions that include the parser message and the start of the offending input.
PHP bounded round-robin worker pool
Distributes queued jobs across a fixed number of worker slots and returns each result or caught exception.
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.
PHP environment config with validation
Reads environment variables with defaults and regex validation, failing fast on missing or malformed values.
PHP token bucket rate limiter
Allows short bursts up to the bucket size while enforcing a steady average request rate over time.
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.
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.
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.
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.
PHP deep clone and recursive array merge
Recursively copies nested arrays and objects, then merges overrides without mutating the original structures.
PHP retry helper with capped exponential backoff
Runs a callable with capped exponential backoff and jitter, rethrowing the last error after the final attempt.