← Back to All Articles

Arr::after() in Laravel: Filling the Gap with laravel-arr-extended

By Gulfaraz Arshad • Published November 17, 2026 • 5 min read
Laravel PHP 8.1+ Open Source Packagist

The Missing Helper in Illuminate\Support\Arr

Laravel's Arr utility class covers dozens of everyday array operations—from Arr::first() and Arr::last() to Arr::get() and Arr::pluck(). Yet there is no expressive, single-call helper to retrieve the element immediately after a given value in an array.

In native PHP, writing that lookup manually means chaining array_search($value, $array, true), guarding against false, re-indexing keys with array_values() if the array is associative, and checking bounds before reading $values[$index + 1].

I originally submitted this helper as Laravel Framework PR #60081. To keep the core framework surface minimal, Taylor Otwell declined merging it into core—so I packaged and published it as gulfaraz-arshad/laravel-arr-extended for Laravel 11.x and 12.x.

Installation & Method Signature

Install the package via Composer in any PHP 8.1+ and Laravel 11 or 12 application:

composer require gulfaraz-arshad/laravel-arr-extended

The Arr::after() method accepts three parameters:

<?php

use GulfarazArshad\LaravelArrExtended\Arr;

Arr::after(array $array, mixed $value, bool $wrap = false): mixed

Core Capabilities & Edge Cases

  • Predictable boundary handling: Returns null when the target is the last element, when the value is absent, or when the array is empty.
  • Circular wrap-around (wrap: true): Passing wrap: true wraps seamlessly from the final item back to the first item—ideal for round-robin queues and cyclic schedules.
  • Associative array support: Works cleanly on string-keyed associative arrays such as ['x' => 'a', 'y' => 'b'] without losing positional order.
  • Strict type comparison: Uses strict equality (===) so Arr::after([1, 2, 3], '1') safely returns null instead of falling victim to PHP type juggling.

Practical Production Use Cases

In production Laravel applications, sequential array transitions show up everywhere—multi-step onboarding wizards, round-robin server/provider selection, and recurring weekly schedules:

<?php

use GulfarazArshad\LaravelArrExtended\Arr;

// 1. Multi-step checkout or onboarding wizard
$steps = ['personal', 'address', 'payment', 'confirm'];
$nextStep = Arr::after($steps, 'payment'); // 'confirm'
$isDone   = Arr::after($steps, 'confirm'); // null (wizard complete)

// 2. Round-robin SMS gateway / worker rotation
$gateways = ['gateway-primary', 'gateway-secondary', 'gateway-backup'];
$nextGateway = Arr::after($gateways, 'gateway-backup', wrap: true); // 'gateway-primary'

// 3. Weekly schedule rotation
$days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
$tomorrow = Arr::after($days, 'Sun', wrap: true); // 'Mon'

You can inspect the full source code, PHPUnit test suite, and contribute additional array helpers on GitHub or install it directly from Packagist.

Gulfaraz Arshad

Written by Gulfaraz Arshad

Software Developer at Cruise Brains specializing in Laravel, PHP, MySQL performance optimization, and high-throughput API architectures.