Skip to content

Instantly share code, notes, and snippets.

@eslavon
Last active October 17, 2019 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eslavon/43ba0f6a4eed6e864d1d2848f52e1545 to your computer and use it in GitHub Desktop.
Save eslavon/43ba0f6a4eed6e864d1d2848f52e1545 to your computer and use it in GitHub Desktop.
Удаление элемента из многомерного массива
<?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