sortowanie asocjacyjnej tablicy po 2 kluczach


  foreach ($normalLinks as $linkId => $data) {
            // prepare additional parameters from link
            // find link
            /* @var $link Linki */
            $link = $this->linksRepository->find($linkId);
            // norlam link CPL
            if (isset($data['linkUrl']) && $data['linkUrl'] != '') {
                // save to result
                $result[$linkId] = [
                    'partnerName' => $transaction->getPartnerNameLinkId($linkId),
                    'redirectUrl' => $data['linkUrl'],
                    'logoSrc' => $link ? $link->getLogoSrc() : null,
                    'description' => $link ? $link->getDescription() : null,
                    'customOrderNr' =>$link ? $link->getCustomOrderNr():null,
                    'orderNr' => isset($data['orderNr']) ? $data['orderNr'] : 99999,
                ];
            }
        }
        
        //sort by customOrderNr and orderNr
        uasort($result, function ($a, $b) {
            $customOrderNrDiff = $a['customOrderNr'] - $b['customOrderNr'];
            return $customOrderNrDiff ?  $customOrderNrDiff: $a['orderNr'] - $b['orderNr'];
        });

        return $result;

Sortowanie malejąco:

uasort($parseLogs['fields'], function ($a, $b) {
    if ($a['numberOfErrors'] == $b['numberOfErrors']) {
       return 0;
    }

    return $a['numberOfErrors'] < $b['numberOfErrors'] ? 1 : -1;
});
Komentarze wyłączone