function getMaxSkill(array $array, int $resource): ?A
{
return array_reduce(
$array,
fn($carry, $item) =>
$item->getCost() <= $resource
&& ($carry === null || $carry->getSkill() < $item->getSkill())
? $item
: $carry,
null
);
}
If the ONLY_FULL_GROUP_BY SQL mode is enabled (which it is by default), MySQL rejects queries for which the select list, HAVING condition, or ORDER BY list refer to nonaggregated columns that are neither named in the GROUP BY clause nor are functionally dependent on them.
MySQL also permits a nonaggregate column not named in a GROUP BY clause when SQL ONLY_FULL_GROUP_BY mode is enabled, provided that this column is limited to a single value
function genWords($alphabet, $length) {
$alph = mb_str_split($alphabet);
$maxChar = count($alph);
$idxs = array_fill(0, $length, 0);
while (true) {
yield implode('', array_map(fn($idx) => $alph[$idx], $idxs));
$pos = $length - 1;
while (true) {
$idxs[$pos] += 1;
if ($idxs[$pos] < $maxChar) {
break;
}
$idxs[$pos] = 0;
$pos -= 1;
if ($pos < 0) {
return;
}
}
}
}
foreach (genWords('АБВГДЕЁЖЗ', 5) as $word) {
print "{$word}\n";
}
function isSeq3(int $number) : bool
{
$prevDigit = 0;
$seqLen = 0;
while ($number > 0) {
$digit = $number % 10;
if ($digit === $prevDigit - 1) {
$seqLen += 1;
} else {
$seqLen = 1;
}
if ($seqLen === 3) {
return true;
}
$number = intdiv($number, 10);
$prevDigit = $digit;
}
return false;
}