$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); } }