Originally published by Hardik Savani at https://itsolutionstuff.com
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:
Example:
<?php$myArray = [
‘name’=>‘Hardik Savani’,
‘email’=>‘savanihd@gmail.com’,
‘gender’=>‘male’,
‘website’=>‘itsolutionstuff.com’
];$newArray = array_except($myArray, [‘gender’, ‘email’]);
print_r($newArray);
function array_except($array, $keys){
foreach($keys as $key){
unset($array[$key]);
}
return $array;
}
?>
Output:
Array
(
[name] => Hardik Savani
[website] => itsolutionstuff.com
)
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
☞ 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