If you want to group based on fromcity and tocity, you can do the following:$count = [];foreach($result_array as $element) { $search = $element['fromcity']. '-'. $element['tocity']; if(!isset($count[$search])) { $count[$search] = 1; } else { $count[$search] += 1; }}//Result:foreach($count as $name => $cnt) { echo $name.' - '. $cnt .PHP_EOL;} 这篇关于根据php中的多个键值对值进行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!