How to Remove Key from Array in Laravel?

Today now in this post i will show you How to Remove Key from Array in Laravel? Sometimes, we need to delete the specific key from an array as like we have password and the confirm-password field but we don’t need to store confirm-password field then we need to drop that key from our input array, so At that time we always use unset() function of PHP pre-define.

We can remove key from an array in laravel 6, laravel 7 and laravel 8 by using array helper.

But if we are working on laravel then we can use array helper function. we can remove the multiple key from variable by using array_except() of Laravel pre-define function.

So now in bellow example we can understand this very well.

Example 1:
$myArray = ['name'=>'HD','email'=>'','password'=>'123456','confirm-password'=>'123456'];
$myArray = Arr::except($myArray,['confirm-password']);
Example 2:
$myArray = ['name'=>'HD','email'=>'','password'=>'123456','confirm-password'=>'123456'];
$myArray = array_except($myArray,['confirm-password']);

Read Also : How to Create Custom Blade Directive in Laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook.


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →