$array = [ 'person' => [ 'name' => 'John Doe', 'age' => 25, 'address' => [ 'street' => '123 Main St', 'city' => 'Anytown', 'state' => 'CA', 'zip' => '12345' ] ] ]; Arr::set_path($array, 'person.address.city', 'New York'); // Output /* $array = [ 'person' => [ 'name' => 'John Doe', 'age' => 25, 'address' => [ 'street' => '123 Main St', 'city' => 'New York', // Updated value 'state' => 'CA', 'zip' => '12345' ] ] ]; */
$arr = []; // Set the value at the path 'person.name' Arr::set_path($arr, 'person.name', 'John Doe'); // Set the value at the path 'person.age' Arr::set_path($arr, 'person.age', 25); // Set the value at the path 'person.address.city' Arr::set_path($arr, 'person.address.city', 'Anytown'); // Output /* $array = [ 'person' => [ 'name' => 'John Doe', 'age' => 25, 'address' => [ 'city' => 'Anytown' ] ] ]; */This example shows how to create a nested array with three values: name, age, and address city. Package Library: Laravel Arr is a package library that provides several helper functions for working with arrays. Arr::set_path is one of the functions provided by this library.