I have a multi-array like this:
array(2) {
[0]=>
array(8) {
[0]=>
string(1) "3"
["Id"]=>
string(1) "3"
[1]=>
string(8) "Portugal"
["Country"]=>
string(8) "Portugal"
[2]=>
string(8) "sometext"
["Type"]=>
string(8) "sometext"
[3]=>
string(1) "0"
["xptoabcdef"]=>
string(1) "0"
}
[1]=>
array(8) {
[0]=>
string(1) "4"
["Id"]=>
string(1) "4"
[1]=>
string(8) "Portugal"
["Country"]=>
string(8) "Portugal"
[2]=>
string(8) "sometext"
["Type"]=>
string(8) "sometext"
[3]=>
string(2) "22"
["xptoabcdef"]=>
string(2) "22"
}
How can I delete the "Country" column from the array in the most simple way?
Try something with array_map()
$new_array = array_map(function($v) {
unset($v['Country']);
return $v;
}, $old_array);
Demo.
You could use array_map()
with a callback function to achieve this:
$array = array_map(function($elem) {
unset($elem['Country']);
return $elem;
}, $array);
Or use a foreach
loop and pass the value by reference, like so:
foreach ($array as $key => & $value) {
unset($value['Country']);
}
Demo!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With