是否有一个 PHP 代码片段或一个内置的数组函数可以做类似于具有和分组依据的 sql 语句的功能?那就是删除重复项并计算出现次数,并返回一个可用于报告/调试目的的数组。
一个例子可以澄清;
说你的数组是这样的
Array (
['0'] => usa
['1'] => minnesota
['2'] => california
['3'] => san fransisco
['4'] => los angeles
['5'] => san fransisco
['6'] => malibu
['7'] => malibu
['8'] => malibu
['9'] => usa
}
你想要这样的东西,或者这样的东西..
Array (
['usa'] => 2
['minnesota'] => 1
['california'] => 1
['san fransisco'] => 2
['los angeles'] => 1
['malibu'] => 3
}