Arr::undot()
Expand a flat dot-notation array back into a fully nested structure — the inverse of Arr::dot().
Overview
Arr::dot() is well known for flattening nested arrays into dot notation. But its inverse, Arr::undot(), is far less known. It takes a flat array with dot-notation keys and reconstructs the nested structure.
Usage
use Illuminate\Support\Arr;
$flat = [
'user.name' => 'Taylor',
'user.email' => '[email protected]',
'user.address.city' => 'Little Rock',
'user.address.state' => 'AR',
];
Arr::undot($flat);
// [
// 'user' => [
// 'name' => 'Taylor',
// 'email' => '[email protected]',
// 'address' => [
// 'city' => 'Little Rock',
// 'state' => 'AR',
// ],
// ],
// ]
When to Use
- Reconstructing config arrays from flat key-value stores (databases, Redis,
.envoverrides) - Transforming form input that uses dot notation back into nested data
- Processing flattened API responses or CSV imports