Array
(
[0] => Array
(
[word] => автомобил
[max_bid] => 12
)
[1] => Array
(
[word] => автомобил
[max_bid] => 46
)
[2] => Array
(
[word] => автомобил
[max_bid] => 9
)
[3] => Array
(
[word] => продвижен
[max_bid] => 9
)
[4] => Array
(
[word] => автомобил
[max_bid] => 15
)
[5] => Array
(
[word] => автомобил
[max_bid] => 22
)
[6] => Array
(
[word] => продвижен
[max_bid] => 22
)
)
[0] => Array
(
[word] => автомобил
[max_bid] => 46
)
[1] => Array
(
[word] => продвижен
[max_bid] => 22
)
$rr_wordz = array();
foreach($rr_word as $row_arra){
if($row_arra['word'] !== $arr_word && $row_arra['max_bid'] > $arr_max_bid){
$arr_word = $row_arra['word'];
$arr_max_bid = $row_arra['max_bid'];
$rr_wordz[]['word'] = $row_arra['word'];
$rr_wordz[]['max_bid'] = $row_arra['max_bid'];
}
}
Array
(
[0] => Array
(
[word] => автомобил
)
[1] => Array
(
[max_bid] => 12
)
[2] => Array
(
[word] => продвижен
)
[3] => Array
(
[max_bid] => 22
)
)
$word = array();
$max_bid = array();
for ($i = 0; $i < count($rr_word); $i++) {
$word[] = $rr_word[$i]['word'];
$max_bid[] = $rr_word[$i]['max_bid'];
}
array_multisort($word, SORT_ASC, $max_bid, SORT_DESC);
$word = array_unique($word);
$result = array();
foreach ($word as $key => $value) {
$result[] = array(
'word' => $value,
'max_bid' => $max_bid[$key],
);
}
Array
(
[0] => Array
(
[word] => автомобил
[max_bid] => 46
)
[1] => Array
(
[word] => продвижен
[max_bid] => 22
)
)
$groupMakesByWord = array();
foreach ($makes as $make) {
$groupMakesByWord[$make['word']][] = $make;
}
foreach ($groupMakesByWord as $makeWord => &$makes) {
uasort($makes, function($a, $b) {
if ($a['max_bid'] == $b['max_bid']) {
return 0;
}
return $a['max_bid'] < $b['max_bid'] ? 1 : -1;
});
}
unset($makes);
$result = array();
foreach ($groupMakesByWord as $makes) {
$result[] = current($makes);
}