Loading .gitignore 0 → 100644 +1 −0 Original line number Diff line number Diff line .vendor No newline at end of file index.php +8 −7 Original line number Diff line number Diff line Loading @@ -2,8 +2,9 @@ require_once __DIR__ . '/vendor/autoload.php'; $func = new Hp\Test\Functions(); use Hp\Test\Functions; $func = new Functions(); ?> <!DOCTYPE html> Loading public/text.txtdeleted 100644 → 0 +0 −2 Original line number Diff line number Diff line Раз, два, три, четыре, Пять, шесть, семь, восемь. No newline at end of file src/Functions.php +25 −18 Original line number Diff line number Diff line <?php namespace Hp\Test; declare(strict_types=1); use DateTimeImmutable; use DateTime; use DateInterval; use DatePeriod; namespace Hp\Test; class Functions { class Functions { /** * Выполняет сортировку массива по убыванию цены * * @param array $array * * Выполняет сортировку массива по убыванию цены * @param array $array * @return array */ function sortPrice(array $array): array { array_multisort(array_column($array, 'price'), SORT_DESC, array_column($array, 'count'), SORT_ASC, $array); public function sortPrice(array $array): array { $prices = array_column($array, 'price'); $counts = array_column($array, 'count'); array_multisort( $prices, SORT_DESC, $counts, SORT_ASC, $array ); return $array; } //На выход должна вернуть отсортированный массив по ключу *price* DESC и во вторую очередь по *count* ASC: //[ ['price'=>12, 'count'=>4], ['price'=>10, 'count'=>2], ['price'=>8, 'count'=>4], //['price'=>8, 'count'=>5], ['price'=>5, 'count'=>5], ] /** * На выход должна вернуть отсортированный массив по ключу *price* DESC * и во вторую очередь по *count* ASC: * [['price'=>12, 'count'=>4], ['price'=>10, 'count'=>2], ['price'=>8, 'count'=>4], * ['price'=>8, 'count'=>5], ['price'=>5, 'count'=>5],] */ } No newline at end of file Loading
.gitignore 0 → 100644 +1 −0 Original line number Diff line number Diff line .vendor No newline at end of file
index.php +8 −7 Original line number Diff line number Diff line Loading @@ -2,8 +2,9 @@ require_once __DIR__ . '/vendor/autoload.php'; $func = new Hp\Test\Functions(); use Hp\Test\Functions; $func = new Functions(); ?> <!DOCTYPE html> Loading
public/text.txtdeleted 100644 → 0 +0 −2 Original line number Diff line number Diff line Раз, два, три, четыре, Пять, шесть, семь, восемь. No newline at end of file
src/Functions.php +25 −18 Original line number Diff line number Diff line <?php namespace Hp\Test; declare(strict_types=1); use DateTimeImmutable; use DateTime; use DateInterval; use DatePeriod; namespace Hp\Test; class Functions { class Functions { /** * Выполняет сортировку массива по убыванию цены * * @param array $array * * Выполняет сортировку массива по убыванию цены * @param array $array * @return array */ function sortPrice(array $array): array { array_multisort(array_column($array, 'price'), SORT_DESC, array_column($array, 'count'), SORT_ASC, $array); public function sortPrice(array $array): array { $prices = array_column($array, 'price'); $counts = array_column($array, 'count'); array_multisort( $prices, SORT_DESC, $counts, SORT_ASC, $array ); return $array; } //На выход должна вернуть отсортированный массив по ключу *price* DESC и во вторую очередь по *count* ASC: //[ ['price'=>12, 'count'=>4], ['price'=>10, 'count'=>2], ['price'=>8, 'count'=>4], //['price'=>8, 'count'=>5], ['price'=>5, 'count'=>5], ] /** * На выход должна вернуть отсортированный массив по ключу *price* DESC * и во вторую очередь по *count* ASC: * [['price'=>12, 'count'=>4], ['price'=>10, 'count'=>2], ['price'=>8, 'count'=>4], * ['price'=>8, 'count'=>5], ['price'=>5, 'count'=>5],] */ } No newline at end of file