0
我与它的团队名称(这是一个行)CSV名单:计数值,计算前4
Teams
Red
Green | Red | Yellow
Red
Yellow | Green | Yellow
Red
Green
Yellow | Yellow | Red
Red
Green
Red
Yellow
我需要能够计算对于各个颜色和数量前4 和它们出现的次数。
我该怎么做?例如,如果我尝试使用:
$teams = file('count.csv');
$count[] = (array_count_values($colors));
print_r($count);
我得到:
Array ([0] => Array ([Teams ] => 1
[Red ] => 5 [Green | Red | Yellow ] => 1 [Yellow | Green | Yellow ] => 1 [Green ] => 2 [Yellow | Yellow | Red ] => 1 [Yellow] => 1))
这是不是非常有用的。另外,我怎么能比较一下这些洼地来获得前四名?
任何技巧已知如何做到这一点?先谢谢你!
OK闯闯:
$inputfile = 'count.csv';
$inputHandle = fopen($inputfile, "r");
while (($data = fgetcsv($inputHandle, 1024, ",")) !== FALSE) {
$teams = $data[0];
$teams = explode('|', $teams);
}
$count[] = (array_count_values($teams));
print("<pre>".print_r($count, true)."</pre>");
我得到
Array
(
[0] => Array
(
[Yellow] => 1
)
)
我在做什么错?
尝试使用分隔符分隔的函数| –
$ inputfile ='count.csv'; $ inputHandle = fopen($ inputfile,“r”); while(($ data = fgetcsv($ inputHandle,1024,“,”))!== FALSE){ $ teams = $ data [0]; $ teams = explode('|',$ teams); } $ count [] =(array_count_values($ teams)); print(“
”); – Alex