$arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18];
usort(
$arr,
function (int $a, int $b): int {
$result = (($a - 1) % 6) - (($b - 1) % 6);
return $result === 0 ? $a - $b : $result;
}
);
print_r($arr);
/* Array
(
[0] => 1
[1] => 7
[2] => 13
[3] => 2
[4] => 8
[5] => 14
[6] => 3
[7] => 9
[8] => 15
[9] => 4
[10] => 10
[11] => 16
[12] => 5
[13] => 11
[14] => 17
[15] => 6
[16] => 12
[17] => 18
) */
object(Test)#1 (2) {
["name":"Test":private]=>
string(16) "Васенька"
["age"]=>
int(43)
}
class Test#1 (2) {
private $name =>
string(16) "Васенька"
public $age =>
int(43)
}
WITH `cte` (`id`, `row`) AS (
SELECT `id`, ROW_NUMBER() OVER `win`
FROM `product`
WINDOW `win` AS (PARTITION BY `sku` ORDER BY `quantity` = 0, `price`)
)
UPDATE `cte`
JOIN `product` USING (`id`)
SET `product`.`status` = (`cte`.`row` = 1)
UPDATE `product` AS `p`
LEFT JOIN (
SELECT `t`.`sku`, MIN(`p`.`id`) AS `id`
FROM (
SELECT `sku`, MIN(`price`) AS `price`
FROM `product`
WHERE `quantity` != 0
GROUP BY `sku`
) AS `t`
JOIN `product` AS `p`
ON `p`.`sku` = `t`.`sku` AND `p`.`price` = `t`.`price`
WHERE `p`.`quantity` != 0
GROUP BY `t`.`sku`
) AS `i` ON `i`.`id` = `p`.`id`
SET `p`.`status` = (`i`.`id` IS NOT NULL);
class ResponseObject
{
public static function parse(object $data): ResponseObject1|ResponseObject2|ResponseObject3|ResponseObject4
{
switch ($data->type) {
case 'type1':
return new ResponseObject1($data);
case 'type2':
return new ResponseObject2($data);
case 'type3':
return new ResponseObject3($data);
case 'type4':
return new ResponseObject4($data);
}
}
}