yiisoft/arrays
yiisoft/arrays is a lightweight PHP utility library for working with arrays: fetch values by key/path, set and remove nested items, merge and filter data, and perform common transformations. Designed for Yii projects but usable standalone.
Strengths:
Arr helper (e.g., Arr::dot(), Arr::get()) by offering additional functional operations (e.g., Yii\Arrays\ArrayHelper::merge(), Yii\Arrays\ArrayHelper::indexBy()).Fit for Laravel:
Arr helper (e.g., advanced filtering, nested transformations, or Yii-specific utilities like mapWithKeys).Arr helper may lead to redundancy if features are duplicated (e.g., Arr::pluck() vs. ArrayHelper::map()).ArrayHelper namespace) may require adapter classes for Laravel’s autoloading/naming standards.map(), filter(), indexBy() — useful for Eloquent collections or API responses.getValue(), setValue() — parallels Laravel’s Arr but with Yii’s syntax.merge(), multisort(), in() — fills niche use cases (e.g., complex sorting in reports).ArrayHelper is already used (e.g., in Yii2-Laravel hybrids).Arr (e.g., ArrayHelper::get() vs. Arr::get()).ArrayUtils::merge()).Arr vs. Yii’s ArrayHelper to avoid duplication.multisort() on 100K+ items)?Arr (e.g., multi-dimensional sorting, custom indexing).Arr + Collection methods suffice.Arr, Collection, or array_* functions for 80% of use cases.spatie/array-to-object, vlucas/phpdotenv (for config arrays), or league/arraypackage (if broader array tools are needed).Arr/Collection.ArrayHelper::indexBy() vs. Laravel’s Collection::keyBy()).composer require yiisoft/arrays
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->singleton('arrayHelper', function () {
return new \Yii\Arrays\ArrayHelper();
});
}
// app/Facades/ArrayUtils.php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class ArrayUtils extends Facade { protected static function getFacadeAccessor() { return 'arrayHelper'; } }
Usage:
use App\Facades\ArrayUtils;
$indexed = ArrayUtils::indexBy($array, 'id');
Yii\Arrays usage in favor of the facade.ArrayHelper::in() → in_array()).Collection methods for database-aware operations.ArrayUtils facade in unit tests for isolated behavior.ArrayHelper may use __callStatic; ensure no conflicts with Laravel’s magic methods.array-key vs. string) align with Laravel’s PSR-12 standards.| Phase | Task | Owner |
|---|---|---|
| Discovery | Map array operations to Laravel/Yii equivalents. | TPM/Dev Lead |
| Pilot | Test in a non-critical module (e.g., reporting). | Backend Dev |
| Facade | Create Laravel-compatible facade. | Backend Dev |
| Docs | Update internal docs with usage patterns. | Tech Writer |
| Deprecate | Replace direct Yii\Arrays calls in legacy code. |
Dev Team |
| Monitor | Track performance/memory usage in production. | SRE/TPM |
arrays package is stable; BSD-3-Clause allows forks if needed.arrays package is abandoned, fork or migrate to Laravel-native solutions.dd() or dump() for array inspection; no special Yii tools needed.ArrayHelper may throw exceptions for invalid inputs; wrap in try-catch if needed.laravel + yiisoft/arrays for visibility.indexBy() uses array_walk under the hood).multisort() may be O(n log n); test with 10K+ items.xdebug.max_nesting_level if needed).ArrayHelper::multisort()) using Laravel’s cache drivers.How can I help you explore Laravel packages today?