douzhi7070 2011-08-26 16:29
浏览 39

如何按字母顺序对PHP中的数组进行排序? [重复]

Possible Duplicates:
How to sort a multi dimensional array in PHP alphabetically?
PHP : Sort array alphabetically

I am developing an API using Codeigniter and Phils RESTserver. In this API I access a database that contains users.

I would like to sort these users before outputting them. How can I do this? I tried the below code but that does not work.

function sort_by_lastname($a, $b)
{
    return strcmp($a['user']['basic']['lastname'], $a['user']['basic']['lastname']);
}

This is my data in JSON format.

http://pastie.org/2402372

How can I alter the above to sort this output (when in PHP array format, not JSON).

Thankful for all help!

  • 写回答

3条回答 默认 最新

  • dongliao1949 2011-08-26 16:32
    关注

    Check PHP.net before asking here. A quick search would have turned up PHP's asort() function: http://php.net/asort

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程