Commit 10ae9b00 authored by Akex's avatar Akex
Browse files

create test data | create sort func

parent 2a7f91b8
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
<?php

namespace App\Actions;

class SortPriceAction
{
    /**
     * Выполняет сортировку массива по убыванию цены
     * @param array $array
     * @return array отсортированный
     */
    public static function sort(array $array)
    {
        $priceColumn = array_column($array, "price");
        $countColumn = array_column($array, "count");

        array_multisort(
            $priceColumn
            ,SORT_DESC
            ,$countColumn
            , SORT_ASC
            ,$array
        );

        return $array;
    }
}
+22 −1
Original line number Diff line number Diff line
@@ -8,5 +8,26 @@ namespace App\TestData;

class TestData
{

    public const PRICE_COUNT_ARRAY = [
        [
            'price' => 4,
            'count' => 2,
        ],
        [
            'price' => 4,
            'count' => 1,
        ],
        [
            'price' => 2,
            'count' => 10,
        ],
        [
            'price' => 1,
            'count' => 4,
        ],
        [
            'price' => 3,
            'count' => 4,
        ],
    ];
}
+2 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

require_once __DIR__ . '/../vendor/autoload.php';

use App\Actions /*placeholder for a class */;
use App\Actions\SortPriceAction;
use App\TestData\TestData;

var_dump(SortPriceAction::sort(TestData::PRICE_COUNT_ARRAY));