Have you ever been working with a Laravel array and thought, “I really wish there was an Arr::after() method right now”?
I did — so I submitted a PR to Laravel core.
The idea was simple: a helper that returns the element immediately after a given value in an array.
The PR didn’t make it into the framework, which is completely understandable. Laravel intentionally keeps the core lean, and not every utility belongs there.
Instead of dropping the idea, I added it to my package: Laravel Arr Extended.
Introducing Arr::after()
With Laravel Arr Extended, you can now do this:
use GulfarazArshad\LaravelArrExtended\Arr;
Arr::after(['a', 'b', 'c'], 'a');
// 'b'
It also supports wrap-around behavior:
Arr::after(['a', 'b', 'c'], 'c', wrap: true);
// 'a'
It works with associative arrays too:
Arr::after(['x' => 'a', 'y' => 'b'], 'a');
// 'b'
Why I Added It
I kept finding myself rewriting the same combination of:
array_search()- manual index calculations
- repetitive edge-case handling
Arr::after() makes that logic reusable, readable, and consistent.
Installation
composer require gulfaraz-arshad/laravel-arr-extended
Check It Out
Package: gulfaraz-arshad/laravel-arr-extended
Top comments (0)