<?php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; class HomeController extends AbstractController { private function sortPrice(array $array): array { $price = []; $count = []; foreach ($array as $key => $row) { $price[$key] = $row['price']; $count[$key] = $row['count']; } array_multisort($price, SORT_DESC, $count, SORT_ASC, $array); return $array; } #[Route('/', name: 'home')] public function home(): Response { $array = array( ['price'=>10, 'count'=>2], ['price'=>5, 'count'=>5], ['price'=>8, 'count'=>5], ['price'=>12, 'count'=>4], ['price'=>8, 'count'=>4], ); $array = $this->sortPrice($array); return $this->json($array); } }