使用PHP在特定列中计算CSV文件中的行数

使用PHP在特定列中计算CSV文件中的行数,php,csv,Php,Csv,我让我的php计算完整csv文档中的行数,但尝试获取在特定列中包含数据的行数。这在PHP中是可能的吗 $fp = file('test.csv'); echo count($fp); 您可以使用fgetcsv功能并检查每一行数据 例如,如果要检查第二列中有多少行包含数据,请运行该命令 $data_found = 0; $handle = fopen("test.csv", "r"); while ($data = fgetcsv($handle)) { if ($data[1] != ''

我让我的php计算完整csv文档中的行数,但尝试获取在特定列中包含数据的行数。这在PHP中是可能的吗

$fp = file('test.csv');
echo count($fp);

您可以使用
fgetcsv
功能并检查每一行数据

例如,如果要检查第二列中有多少行包含数据,请运行该命令

$data_found = 0;
$handle = fopen("test.csv", "r");
while ($data = fgetcsv($handle))
{
  if ($data[1] != '')
  {
    // check the data specifically in the second column
    $data_found ++;
  }
}
echo 'Rows with data in the second column:'.$data_found;

您可以使用
fgetcsv
功能并检查每一行数据

例如,如果要检查第二列中有多少行包含数据,请运行该命令

$data_found = 0;
$handle = fopen("test.csv", "r");
while ($data = fgetcsv($handle))
{
  if ($data[1] != '')
  {
    // check the data specifically in the second column
    $data_found ++;
  }
}
echo 'Rows with data in the second column:'.$data_found;

您可以使用
fgetcsv
功能并检查每一行数据

例如,如果要检查第二列中有多少行包含数据,请运行该命令

$data_found = 0;
$handle = fopen("test.csv", "r");
while ($data = fgetcsv($handle))
{
  if ($data[1] != '')
  {
    // check the data specifically in the second column
    $data_found ++;
  }
}
echo 'Rows with data in the second column:'.$data_found;

您可以使用
fgetcsv
功能并检查每一行数据

例如,如果要检查第二列中有多少行包含数据,请运行该命令

$data_found = 0;
$handle = fopen("test.csv", "r");
while ($data = fgetcsv($handle))
{
  if ($data[1] != '')
  {
    // check the data specifically in the second column
    $data_found ++;
  }
}
echo 'Rows with data in the second column:'.$data_found;

这是可能的!你是怎么数行的?请编辑您的帖子,使其包含适当的代码段。是的,我尝试了数列和其他方法,但似乎无法理解。这是可能的!你是怎么数行的?请编辑您的帖子,使其包含适当的代码段。是的,我尝试了数列和其他方法,但似乎无法理解。这是可能的!你是怎么数行的?请编辑您的帖子,使其包含适当的代码段。是的,我尝试了数列和其他方法,但似乎无法理解。这是可能的!你是怎么数行的?请编辑您的帖子,使其包含适当的代码片段。是的,我尝试过计算列数和其他方法,但似乎无法理解。