Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
$data = [
['name' => 'Название', 'brand' => 'Производитель', 'price' => 100],
['name' => 'Название', 'brand' => 'Производитель', 'price' => 120],
['name' => 'Другое название', 'brand' => 'Производитель', 'price' => 300]
];
$res = array_reduce(
$data,
function($res, $el) {
if (!isset($res[$el['name'].$el['brand']])) {
$res[$el['name'].$el['brand']] = $el;
} elseif (
$res[$el['name'].$el['brand']]['price'] > $el['price']
) {
$res[$el['name'].$el['brand']]['price'] = $el['price'];
}
return $res;
},
[]
);
print_r(array_values($res));