Couting各值的出现以阵列 [英] Couting occurrences of each value in an array

查看:109
本文介绍了Couting各值的出现以阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想排序和拼接一个数组,但我发现它非常混乱。

I'm trying to sort and splice an array, however I'm finding it very confusing.

我从一个MySQL表拉着我的数据:

I have pulled my data from a mysql table:

$total = mysql_query("SELECT * FROM orders");

我那么每列排序到一个数组:

I am then sorting each column into an array:

while($result = mysql_fetch_assoc($total))
{
 $cst[] = $result['customer'];
 $partnumber[] = $result['partnumber'];
 $misc[] = $result['misc'];
}

现在,杂项有以随机顺序重复的条目例如

now, misc has many entries that repeat in a random order e.g.

$misc = array(
              [0] => red, 
              [1] = >red, 
              [2] => blue, 
              [3] => blue, 
              [4] => blue,
              [5] => green,
              [6] =>red
              )

问:什么是计算在$其它各红色,蓝色或绿色的元素数量的最佳方式?我怎么能创建一个数组,这样 $ misc_num ['红'] = 3 等。

推荐答案

使用的 array_count_values​​

这篇关于Couting各值的出现以阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆