arraypress / wp-array-utils
Essential array operations for WordPress development - lean, focused, and practical
v1.0.0
2026-08-25 15:44 UTC
Requires
- php: >=8.3
Requires (Dev)
- phpcompatibility/phpcompatibility-wp: ^2.1
- phpunit/phpunit: ^12.0
- squizlabs/php_codesniffer: ^3.13.5
- wp-coding-standards/wpcs: ^3.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-04 17:32:24 UTC
README
Array operations that WordPress and PHP leave you to write yourself.
What it does
Most of what a plugin does to an array is the same handful of moves: reach into
a nested config with a dotted path, group rows by a column, pull one column out
of a result set, or turn a list into the label/value pairs a <select> wants.
Each is three or four lines on its own, so each gets written again in every project, slightly differently. This is the one copy.
Features
- Read and write nested values with a dotted path, without checking each level
- Keep only certain keys, or drop certain keys
- Group rows by a column, or pluck a single column out of them
- Sort by value, by key, or by a column in a result set
- Turn a list into
<select>options, and back again - Insert an item before or after a named key, keeping the order
- Flatten a nested array, optionally removing duplicates
- Compare two arrays for any shared value, or for all of them
Installation
composer require arraypress/wp-array-utils
Quick start
use ArrayPress\ArrayUtils\Arr; // Reach into a nested settings array without four isset() checks. $currency = Arr::get( $settings, 'checkout.currency.code', 'USD' ); // Orders in, orders grouped by status out. $by_status = Arr::group_by( $orders, 'status' ); // Just the customer ids from a result set. $customer_ids = Arr::pluck( $orders, 'customer_id' ); // A list ready for a <select>. $options = Arr::to_options( $gateways, 'label' );
Requirements
- PHP 8.3 or later
- WordPress 7.1 or later
License
GPL-2.0-or-later