Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Удаление элемента из многомерного массива
<?php
$ids = array_column($array, "address");
$ids = array_unique($ids);
$result_array = array_filter(
$array,
function ($key, $value) use ($ids) {
return in_array($value, array_keys($ids));
},
ARRAY_FILTER_USE_BOTH
);
<?php
array(10) {
[0]=> array(4) {
["country"]=> string(12) "Россия"
["address"]=> string(36) "Ивановская область"
["longitude"]=> float(40.97374)
["latitude"]=> float(56.998444)
}
[1]=> array(4) {
["country"]=> string(16) "Беларусь"
["address"]=> string(34) "Брестская область"
["longitude"]=> float(25.531807)
["latitude"]=> float(52.142063)
}
[2]=> array(4) {
["country"]=> string(12) "Россия"
["address"]=> string(36) "Московская область"
["longitude"]=> float(39.227577)
["latitude"]=> float(55.379974)
}
}
<?php
array(10) {
[0]=> array(4) {
["country"]=> string(12) "Россия"
["address"]=> string(36) "Ивановская область"
["longitude"]=> float(40.97374)
["latitude"]=> float(56.998444)
}
[1]=> array(4) {
["country"]=> string(16) "Беларусь"
["address"]=> string(34) "Брестская область"
["longitude"]=> float(25.531807)
["latitude"]=> float(52.142063)
}
[2]=> array(4) {
["country"]=> string(12) "Россия"
["address"]=> string(36) "Ивановская область"
["longitude"]=> float(40.980137)
["latitude"]=> float(57.018)
}
[3]=> array(4) {
["country"]=> string(12) "Россия"
["address"]=> string(36) "Московская область"
["longitude"]=> float(39.227577)
["latitude"]=> float(55.379974)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment