gulfaraz-arshad / laravel-arr-extended
Extended Arr helpers for Laravel including Arr::after()
Package info
github.com/gulfaraz-arshad/laravel-arr-extended
pkg:composer/gulfaraz-arshad/laravel-arr-extended
Requires
- illuminate/support: ^11.0|^12.0
Requires (Dev)
- phpunit/phpunit: ^11.5
README
Extended Arr helpers for Laravel — filling the small gaps that Laravel's built-in Arr class doesn't cover.
Why This Package?
Laravel's Arr class provides helpful methods like Arr::first() and Arr::last() — but there's no clean way to get the value after a given value in an array. This package fills that gap.
I originally submitted this as a PR to the Laravel framework. Taylor decided to keep the framework minimal, so I released it as a standalone package instead.
Requirements
- PHP 8.1+
- Laravel 11.x or 12.x
Installation
composer require gulfaraz-arshad/laravel-arr-extended
Available Methods
Arr::after()
Retrieves the value after a given value in an array.
use GulfarazArshad\LaravelArrExtended\Arr; Arr::after(array $array, mixed $value, bool $wrap = false): mixed
Basic Usage
// Returns the value after 'a' Arr::after(['a', 'b', 'c'], 'a'); // 'b' // Last element returns null by default Arr::after(['a', 'b', 'c'], 'c'); // null // Value not found returns null Arr::after(['a', 'b', 'c'], 'z'); // null // Empty array returns null Arr::after([], 'a'); // null
With wrap Flag
// Last element wraps to first Arr::after(['a', 'b', 'c'], 'c', wrap: true); // 'a' // Value not found with wrap returns first element Arr::after(['a', 'b', 'c'], 'z', wrap: true); // 'a'
Associative Arrays
// Works with associative arrays Arr::after(['x' => 'a', 'y' => 'b'], 'a'); // 'b'
Type Safety
// Strict comparison — no type juggling Arr::after([1, 2, 3], '1'); // null (string !== integer) Arr::after([1, 2, 3], 1); // 2 ✅
Real World Examples
Step wizard:
$steps = ['personal', 'address', 'payment', 'confirm']; $next = Arr::after($steps, 'payment'); // 'confirm' $done = Arr::after($steps, 'confirm'); // null — wizard complete!
Carousel navigation:
$slides = ['home', 'about', 'contact']; $next = Arr::after($slides, 'contact', wrap: true); // 'home'
Round-robin load balancing:
$servers = ['server1', 'server2', 'server3']; $next = Arr::after($servers, 'server3', wrap: true); // 'server1'
Day of week rotation:
$days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; $next = Arr::after($days, 'Sun', wrap: true); // 'Mon'
Testing
./vendor/bin/phpunit
Contributing
Contributions are welcome! If you have ideas for other array helpers that are missing from Laravel, feel free to open an issue or submit a PR.
Credits
License
MIT