duanli9930 2014-10-01 07:34
浏览 38

php排序合并数组

I have a list of (xml) items, each item has a category and a name:

Category | Name

1         |  Joe
2         |  Carol
3         |  Bruce
1         |  Michael     
1         |  Alan
2         |  Brian

I want to sort the names ascending within categories descending like so:

Category | Name

3         |  Bruce
2         |  Brian
2         |  Carol
1         |  Alan
1         |  Joe
1         |  Michael

with the aim of creating a Select dropdown on a web page with each category as an OptGroup and the names sorted within the OptGroup. I have very little experience with PHP, I think I need to sort merge arrays, but after many hours trying to understand how to, I'm not making much progress. Any help greatly appreciated

  • 写回答

3条回答 默认 最新

  • duanhao4156 2014-10-01 07:46
    关注
    $name = array("Joe", "Carol", "Bruce", "Michael","Alan","Brian");
    sort($name);
    

    php-in built function sort will produce desire result

    评论

报告相同问题?

悬赏问题

  • ¥15 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!