How to remove multiple keys from PHP Array?

Originally published by Hardik Savani at

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’,

$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…

Thanks for reading

If you liked this post, share it with all of your programming buddies!

Follow us on Facebook | Twitter

Learn More

PHP for Beginners - Become a PHP Master - CMS Project

Learn Object Oriented PHP By Building a Complete Website

PHP OOP: Object Oriented Programming for beginners + Project

Laravel PHP Framework Tutorial - Full Course for Beginners (2019)

Symfony PHP Framework - Full Course

What is a Full Stack Developer?

Build RESTful API In Laravel 5.8 Example

Laravel 5.8 Tutorial from Scratch for Beginners

Build a CRUD Operation using PHP & MongoBD

#php #laravel #web-development

How to remove multiple keys from PHP Array?
142.00 GEEK