Kmspico Download | Official KMS Activator Website [New Version 2024] Uw betrouwbare online apotheek Drogisterij Unique in Nederland Vavada вход позволяет мгновенно попасть в мир азартных игр и бонусов! Получи доступ и начни выигрывать прямо сейчас.

Using Arr::forget() in Laravel 11.x

In Laravel 11.x, you can use `Arr::forget()` to remove one or multiple keys from an array, including nested keys.

Syntax

Arr::forget(array &$array, string|array $keys)

`$array` → The array from which you want to remove elements.
`$keys` → The key(s) to forget (can be a string or an array).

Example 1: Remove a Single Key

use Illuminate\Support\Arr;

$data = ['name' => 'John', 'email' => 'john@example.com', 'age' => 30];
Arr::forget($data, 'email');

print_r($data);

Output:-

Array
(
[name] => John
[age] => 30
)

Example 2: Remove Multiple Keys

use Illuminate\Support\Arr;

$data = ['name' => 'John', 'email' => 'john@example.com', 'age' => 30];
Arr::forget($data, ['name', 'age']);

print_r($data);

Output:-

Array
(
[email] => john@example.com
)

Example 3: Remove Nested Keys

use Illuminate\Support\Arr;

$data = [
'user' => [
'name' => 'John',
'email' => 'john@example.com',
'address' => [
'city' => 'New York',
'zip' => '10001'
]
]
];

Arr::forget($data, 'user.address.city');
print_r($data);

Output:-

Array
(
[user] => Array
(
[name] => John
[email] => john@example.com
[address] => Array
(
[zip] => 10001
)
)
)