使用自定义排序对多维数组进行排序

时间:2018-07-16 11:04:02

标签: php arrays sorting

我有如下数组

Array
(
    [0] => Array
        (
            [ToppersCategory] => Array
                (
                    [id] => 1
                    [name] => GSEB HSC 2017 - 2018
                        (
                            [0] => Array
                                (
                                    [Toppers] => Array
                                        (
                                            [id] => 42
                                            [title] => Dave Milauni
                                            [slug] => Dave-Milauni
                                        )

                                ),
                            [1] => Array
                                (
                                    [Toppers] => Array
                                        (
                                            [id] => 42
                                            [title] => Dave Milauni
                                            [slug] => Dave-Milauni
                                        )

                                )

依此类推

现在我想按name中显示的ToppersCategory进行排序,那么我该如何排序。 例如

enter image description here

所以我想展示我想比icse和gseb首先展示isc

我搜索了许多解决方案,例如ksort()array_key_sort(),但没有得到预期的o / p,因此是否有解决方案。显示以下数据的ny代码

foreach ($allcat_data as $newsevents_key => $allcats_data)
{
  if(($allcats_data['ToppersCategory']['id']) == 1)
  {
  ?>
    <a href="#<?php echo mb_substr($allcats_data['ToppersCategory']['slug'], 0, 80);?>" class="active" data-filter=".<?php echo mb_substr($allcats_data['ToppersCategory']['slug'], 0, 80);?>"><?php echo mb_substr($allcats_data['ToppersCategory']['name'], 0, 80);?></a>

  <?php } else { ?>

    <a href="#<?php echo mb_substr($allcats_data['ToppersCategory']['slug'], 0, 80);?>" class="" data-filter=".<?php echo mb_substr($allcats_data['ToppersCategory']['slug'], 0, 80);?>"><?php echo mb_substr($allcats_data['ToppersCategory']['name'], 0, 80);?></a>                     
  <?php
  }
} 

0 个答案:

没有答案