Home Laravel How to Remove Key from Array in Laravel?

How to Remove Key from Array in Laravel?

by Shahriar Sagor

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'=>'test@gmail.com','password'=>'123456','confirm-password'=>'123456'];
$myArray = Arr::except($myArray,['confirm-password']);
Example 2:
$myArray = ['name'=>'HD','email'=>'test@gmail.com','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.


You may also like