In this tutorial, We will learn how to remove array elements by keys array in PHP. We will delete multiple keys from array PHP.
<?php
$myArray = [
'name'=>'Rathorji',
'email'=>'testmail@gmail.com',
'gender'=>'male',
'website'=>'rathrji.in'
];
$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] => Rathorji [website] => rathorji.in ) |
rest of elements are deleted