How to remove multiple keys from PHP Array?

By Hardik Savani | August 21, 2019 | Category : PHP

In this example, we will remove array elements by keys array in php. we can delete multiple keys from array php. basically we will unset multiple keys from php array.

if you see in php documentation there are not available directly remove multiple keys from php array. But we will create our own php custom function and remove all keys by given array value.

In this example i created custom function as array_except(). you need to pass one main array and another will be keys array that you want to remove it.

So let's see bellow example:



$myArray = [

'name'=>'Hardik Savani',

'email'=>'[email protected]',




$newArray = array_except($myArray, ['gender', 'email']);


function array_except($array, $keys){

foreach($keys as $key){



return $array;






[name] => Hardik Savani

[website] =>


I hope it can help you...

Tags : Array PHP

Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. 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, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: