In Laravel 11, `Arr::except()` is a helper function provided by Illuminate\Support\Arr. It allows you to remove specific keys from an array while keeping the rest of the data intact.
Syntax
Arr::except(array $array, array|string $keys): array
`$array`: The original array.
`$keys`: The key or an array of keys to exclude.
1. Removing a Single Key
use Illuminate\Support\Arr;
$data = [
'name' => 'John',
'email' => 'john@example.com',
'age' => 30
];
$result = Arr::except($data, 'email');
print_r($result);
Output:
Array
(
[name] => John
[age] => 30
)
Here, `'email'` is removed from the array.
2. Removing Multiple Keys
use Illuminate\Support\Arr;
$data = [
'name' => 'John',
'email' => 'john@example.com',
'age' => 30,
'city' => 'New York'
];
$result = Arr::except($data, ['email', 'city']);
print_r($result);
Output:
Array
(
[name] => John
[age] => 30
)