Answer the question
In order to leave comments, you need to log in
How to remove array with same values in PHP multidimensional array?
$array = array(
'item-1' => array(
'a' => 'Повторяющееся значение 1',
'b' => 'xx1',
'c' => 'xx2'
),
'item-2' => array(
'a' => 'Повторяющееся значение 1',
'b' => 'xx3',
'c' => 'xx4'
),
'item-3' => array(
'a' => 'Повторяющееся значение 2',
'b' => 'xx5',
'c' => 'xx6'
),
'item-4' => array(
'a' => 'Повторяющееся значение 2',
'b' => 'xx7',
'c' => 'xx8'
)
);
array(
'item-1' => array(
'a' => 'Повторяющееся значение 1',
'b' => 'xx1',
'c' => 'xx2'
)
'item-3' => array(
'a' => 'Повторяющееся значение 2',
'b' => 'xx5',
'c' => 'xx6'
)
);
Answer the question
In order to leave comments, you need to log in
$array = array_map("unserialize", array_unique(array_map("serialize", $array)));
$tmp = [];
foreach ($array as $k => $v) {
if (array_key_exists($v['a'], $tmp)) {
unset($array[$k]);
} else {
$tmp[$v['a']] = true;
}
}
var_dump($array);
Decided by myself:
foreach(array_reverse($array, true) as $id => $item) {
if (in_array($item['a'], array_column(array_slice($array, $id+1), 'a'))) {
unset($array[$id]);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question