How to Remove Key from Array in Laravel?
Sometimes, we require to delete specific key from array like we have password and confirm-password field but we don't require to store confirm-password field we have to drop that key from input array, At that time we always use unset() function of PHP pre-define.
you can remove key from array in laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10 by array helper.
But if you work on laravel then you can array helper function. we can remove multiple key from variable using array_except() of Laravel pre-define function. In bellow example you can understand very well.
Example 1:
$myArray = ['name'=>'HD','email'=>'test@gmail.com','password'=>'123456','confirm-password'=>'123456'];
$myArray = Arr::except($myArray,['confirm-password']);
print_r($myArray);
Example 2:
$myArray = ['name'=>'HD','email'=>'test@gmail.com','password'=>'123456','confirm-password'=>'123456'];
$myArray = array_except($myArray,['confirm-password']);
print_r($myArray);
I hope it can help you...

Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Collection Check If Key Exists Example
- How to Convert Collection to JSON in Laravel?
- Laravel Google Chart Example Tutorial
- Laravel Firebase Push Notification Tutorial
- Laravel Model Events Tutorial
- Laravel Livewire Datatables Example Tutorial
- Laravel Collection Map Method Example
- Laravel Collection Duplicates Method Example
- Laravel Collection SortBy Tutorial with Examples
- Laravel Collection Merge | How to Merge Two Eloquent Collection?
- Laravel Collection Unique | Remove Duplicates from Collection Laravel
- Laravel 8/7 Paginate with Collection or Array
- How to get Keys from Array in PHP Laravel?
- Laravel Order By with Column Value Example
- Laravel CKeditor 5 Image Upload Tutorial Example