<?php
$arr = [
['name' => 'ford', 'count' => 2],
['name' => 'ford', 'count' => 8],
['name' => 'lada', 'count' => 9],
['name' => 'lada', 'count' => 2]
];
$res = array_reduce($arr, function($carry, $item) {
if(!isset($carry[$item['name']]) || ($carry[$item['name']] < $item['count']) ) {
$carry[$item['name']] = $item['count'];
}
return $carry;
});
var_dump($res);
$arr = [['name' => 'ford', 'count' => 2],
['name' => 'ford', 'count' => 8],
['name' => 'lada', 'count' => 9],
['name' => 'lada', 'count' => 2]];
$result = [];
foreach($arr as $car) {
if (!isset($result[$car['name']]) || $result[$car['name']] < $car['count']) {
$result[$car['name']] = $car['count'];
}
}
SELECT to_t.name, to_t.id, to_t2.name, to_t2.id
FROM to_team_games to_t_g
LEFT JOIN to_teams to_t on to_t_g.team_id_1 = to_t.id
LEFT JOIN to_teams to_t2 on to_t_g.team_id_2 = to_t2.id
WHERE to_t_g.id= 1
function extend() {
for (var i = 1; i < arguments.length; i++)
for (var key in arguments[i])
if (arguments[i].hasOwnProperty(key))
arguments[0][key] = arguments[i][key];
return arguments[0];
}
function test(value) {
var defaults = {
check: 0,
point: true
};
return extend(defaults, value);
}
console.log( test() ); // Object { check=0, point=true}
console.log( test({check: 555}) ); // Object { check=555, point=true}
console.log( test({check: 10, point: false}) ); // Object { check=10, point=false}