Download the PHP package nixn/php-util without Composer
On this page you can find all versions of the php package nixn/php-util. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nixn/php-util
More information about nixn/php-util
Files in nixn/php-util
Package php-util
Short Description PHP language utilities, mostly to code more in functional style.
License MIT
Informations about the package php-util
php-util
A PHP library with utility functions, mostly useful when coding in functional style, but also some other stuff.
Installation
Via composer:
Components
Namespace: nixn\php
. All functions (except in Pipe) are static, so they can be called easily
(e.g. Arr::pick($array, 'a', 'b'))
).
Arr (ay)
pick(array $array, string|int ...$keys): array
Returns a new array with only the key => value mappings left, whose keys are in $keys.find_by(array $array, callable $predicate, bool $return_key = false): mixed
Searches for a value in the array, based on the predicate, returning it (or its key) or null, when not found.reduce(array $array, callable $callback, mixed $initial = null): mixed
Like array_reduce(), but the callback passes the key of the element, too.kvjoin(array $data, string $sep = ', ', string $kv_sep = '='): string
Like implode()/join() in legacy syntax, but outputs the keys too and takes an additional parameter$kv_sep
.first(array $array): array
Returns the first mapping (element) of an array as key and value in an array, or null/null if the array is empty.find(array $array, string|int ...$ks): array
Searches for a mapping in the array whose key is one of $keys, returns the key and the value or null/null (if not found) as an array.
Partial
partial(callable $callable, mixed ...$args): callable
Returns a new function, which will call the callable with the provided args and can use placeholders for runtime args.
Str (ing)
trim_prefix(string $string, string $prefix): string
Trims a string prefix when it matches.trim_suffix(string $string, string $suffix): string
Trims a string suffix when it matches.
Util
identity(mixed $v): mixed
Just returns the input value. Useful in functional programming style.map(mixed $v, ?callable $fn = null, bool $null_on_not = false, bool $func = false, bool $null = true, bool $false = false, bool $empty = false, bool $zero = false): mixed
Checks$v
on (selectable) common falsy values and returns$fn($v)
or$v
(when$fn === null
) when not falsy. Returns$v
or null otherwise (depending on$null_on_not
).map_nots(mixed $v, ?callable $fn = null, bool $null_on_not = false, bool $func = false, mixed ... $nots): mixed
Likemap()
, but the falsy values are given as arguments ($nots
).when(mixed $test, mixed $v, ?callable $fn = null, bool $null = true, bool $false = true, bool $empty = false, bool $zero = false): mixed
Returns a value based on$test
,$v
and$fn
, testing based on selectable common falsy values. (See PHPdoc for more information.)when_nots(mixed $test, mixed $v, ?callable $fn = null, mixed ... $nots): mixed
Likewhen()
, but the falsy values are given as arguments ($nots
).tree_path(mixed $element, callable $get_parent, ?callable $while = null): \Generator
For any node in a tree structure, get all parents (possibly up to a specific one) and return them from top to bottom.new(string $class): \Closure
Returns a Closure for a constructor call.
Pipe
A Pipe wraps an intial value and pipes it through any function which modifies it. The resulting value can be accessed at the end.
Example:
License
Copyright © 2025 nix https://keybase.io/nixn
Distributed under the MIT license, available in the file LICENSE.
Donations
If you like php-util, please consider dropping some bitcoins to 1nixn9rd4ns8h5mQX3NmUtxwffNZsbDTP
.