duanjiong1952 2012-04-18 17:54
浏览 223
已采纳

如何为PHP数组获取类似SQL的HAVING和GROUP BY?

Is there a PHP code snippet or a built in array function that would do kind of like what a sql statement with having and group by does? That is removing the dups and counting the occurrences and giving you back an array that you can use for reporting/debugging purposes.

An example may clarify;

say your array is like this

Array (
['0'] => usa
['1'] => minnesota
['2'] => california
['3'] => san fransisco
['4'] => los angeles
['5'] => san fransisco
['6'] => malibu
['7'] => malibu
['8'] => malibu
['9'] => usa
}

and you want something back like this, or something to this effect..

Array (
['usa'] => 2
['minnesota'] => 1
['california'] => 1
['san fransisco'] => 2
['los angeles'] => 1
['malibu'] => 3
}
  • 写回答

3条回答 默认 最新

  • driuwt9557 2012-04-18 17:57
    关注

    http://www.php.net/manual/en/function.array-count-values.php

    You can use the following code to do this:

    array_count_values ($myArray)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作