Loading public/public/Actions/SortPriceAction.php 0 → 100644 +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; } } public/public/TestData/TestData.php +22 −1 Original line number Diff line number Diff line Loading @@ -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, ], ]; } public/public/index.php +2 −1 Original line number Diff line number Diff line Loading @@ -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)); Loading
public/public/Actions/SortPriceAction.php 0 → 100644 +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; } }
public/public/TestData/TestData.php +22 −1 Original line number Diff line number Diff line Loading @@ -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, ], ]; }
public/public/index.php +2 −1 Original line number Diff line number Diff line Loading @@ -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));