Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?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));
Copy Clear