排序多维数组对象

时间:2016-03-25 17:49:20

标签: php arrays sorting multidimensional-array

我正在尝试对这种数组进行排序。 它应按" TotalYearyCostWithBonuses"排序。但它没有用。

这是我试过的

function sortByOrder($a, $b) {
    return $a->Cost->TotalYearyCostWithBonuses - $b->Cost->TotalYearyCostWithBonuses;
}

usort($response->Tariffs, 'sortByOrder');

这是数组

    [10] => stdClass Object
    (
        [LogoImageUrl] => ~/images/anbieter/645211.jpg
        [Tariffs] => Array
            (
                [0] => stdClass Object
                    (
                        [IsTieredTariff] => 
                        [Cost] => stdClass Object
                            (
                                [TotalYearyCostWithBonuses] => 634.550721
                            )

                        [TariffId] => 881723300
                    )

                [1] => stdClass Object
                    (
                        [IsTieredTariff] => 
                        [Cost] => stdClass Object
                            (
                                [TotalYearyCostWithBonuses] => 694.550759
                            )

                        [TariffId] => 881725148
                    )
            )

        [Name] => E WIE EINFACH GmbH
    )

修改 它差不多......现在正在工作;)

foreach($response AS $item) {
  usort($item->Tariffs, 'sortByOrder');
}

0 个答案:

没有答案