In your code you want to remove all arrays in the array $a that have an element with the key "first_name". You are not checking on the actual value. Try this:
function removeElementWithKey($array, $keyToRemove){
foreach($array as $subArray)
{
foreach(array_keys($subArray) as $keyIndex => $key)
{
if ($key == $keyToRemove)
{
array_splice($subArray, $keyIndex, 1);
}
}
}
return $array;
}
$data= removeElementWithKey($a, 'first_name');
print_r($data);
I used array_splice instead of unset(). This will leave your indexing in tact.
You can check the code here :
PHP code- 39 lines - codepad[
^]