我有一个数组,从低到高排序,其中有超过260k的值.我已经发现数组的平均值(平均值)和中位数只需要找出模式?
我不能使用PHP所拥有的任何数学函数,它必须全部手动完成.
我希望它可以只有一个值是模式,但是可以有多个值可以作为模式.我还需要能够记录存储值的次数.例如,数字51出现6次,因此我可以打印这两个值.
到目前为止这是我的代码:
$amountRecords = 0;
$totalValue = 0;
$valueArray = array();
// reads in csv file
$handle = fopen('Task1-DataForMeanMedianMode.csv', 'r');
// to skip the header names/values
fgetcsv($handle);
// creates array containing variables of csv file in ascending order
while(($row = fgetcsv($handle, "\r")) != FALSE)
{
// if amountRecords equals 0
if($amountRecords == 0)
{
// adds value from csv to array
$valueArray[] = $row[1];
} // else amountRecords does not equal 0
else
{
// if the value …Run Code Online (Sandbox Code Playgroud) 我是新来的PHP,并希望能在其中有两列csv文件阅读,一个是数字(有点像一个ID),那么其他持有整数值.我查找了fgetcsv函数,但是我找不到从csv文件中读取特定列的方法.
我想从第二列获得所有值,没有标题.
这样做的任何方式?
这是我到目前为止:
$file = fopen('data.csv', 'r');
$line = fgetcsv($file);
Run Code Online (Sandbox Code Playgroud)
这是来自csv文件的一些示例数据:
ID,Value
1,243.00
2,243.00
3,243.00
4,243.00
5,123.11
6,243.00
7,180.00
8,55.00
9,243.00
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
谢谢.