dskripchenko / php-array-helper
Additional array functions
1.1.3
2026-07-20 15:07 UTC
Requires
- php: ^8.2
- ext-json: *
README
A tiny set of pure-PHP array helpers, autoloaded as global functions.
Requirements
PHP 8.2 – 8.5.
Install
composer require dskripchenko/php-array-helper
The functions are registered via Composer's files autoloading — no setup needed.
Functions
array_merge_deep(array ...$arrays): array
Recursively merges arrays. String keys are merged deeply (nested arrays are combined); integer keys are appended rather than overwritten. Variadic.
array_merge_deep( ['x' => ['a' => 1, 'b' => 2], 'y' => 1], ['x' => ['b' => 3, 'c' => 4], 'z' => 2], ); // ['x' => ['a' => 1, 'b' => 3, 'c' => 4], 'y' => 1, 'z' => 2] array_merge_deep([1, 2], [3, 4]); // [1, 2, 3, 4]
array_sort_deep(array $array, int $flags = SORT_REGULAR): array
Recursively ksort()s the array and every nested array.
array_sort_deep(['b' => 2, 'a' => ['y' => 1, 'x' => 2]]); // ['a' => ['x' => 2, 'y' => 1], 'b' => 2]
array_is_associative(array $array): bool
True when the array has any non-sequential (string / gapped) keys.
array_is_associative(['x' => 1]); // true array_is_associative([1, 2, 3]); // false
array_get_signature(array $array, ?string $secret = null, ?string $salt = null, ?callable $hashing = null, int $flags = JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK): string
A stable, order-independent signature of an array: it deep-sorts the array,
JSON-encodes it, wraps it in secret + payload + salt and hashes the result
(md5 by default, or your own $hashing callable).
array_get_signature(['a' => 1, 'b' => 2]) === array_get_signature(['b' => 2, 'a' => 1]); // true
License
MIT © Denis Skripchenko