How to remove multiple keys from PHP Array?

How to remove multiple keys from PHP Array?

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.

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', 'email'=>'[email protected]', 'gender'=>'male', 'website'=>'' ];

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


function array_except($array, $keys){ foreach($keys as $key){ unset($array[$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

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

PHP Web Application Development Company

As a top **PHP Web Application Development Company in USA**[]( ""), we at Data EximIT have...

PHP Website Development

Skenix Infotech is a leading PHP Web Development Company that helps companies get results with industry best practices. Get affordable PHP Development Services.

Laravel Development Company

Skenix Infotech is a top Laravel Website Development Company with Expert Laravel Developers that provides robust Laravel Development Services at fair costs.

Hire Dedicated PHP Developer

Looking to hire affordable yet experienced PHP developers? **[Hire Dedicated PHP Developer]( "Hire Dedicated PHP Developer")**, who can convert your idea to reality, within the stipulated...

Hire PHP Developer

Looking to develop a PHP based website from scratch or revamp your existing website? **[]( "")** has always been an industry leader for companies and business owners looking to hire...