我试图从使用php的csv文件中包含'New'和'Used'的列中获取总计数

I am trying to get the total count for new and used cars from the column "type" in a csv file. I output the data fine but cant seem to figure out out to split up the new and used count..

Here is what im using -

// Set path to CSV file
$csvFile = 'csv/File.csv';
$csv = readCSV($csvFile);
array_shift($csv); 

$count = count($csv); // Gives Total New and Used (400)

foreach($csv as $car){
$type = $car[0]; // defines New or Used Car
$used = ($type == "Used"); //(Should be 108)
$new = ($type == "New");   //(Should be 292)
}

Now how would I get the total count for each new and used?

This is a very simple logic.

    $used = 0;  $new = 0;
    foreach($csv as $car){
        $type = $car[0]; // defines New or Used Car
        if($type == "Used"){
            $used++; //(Should be 108)
        } 
        if($type == "New"){
            $new++; //(Should be 292)
        }   
    }
echo "Used Cars : ". $used ."<br>";
echo "New Cars : ". $new ."<br>";

try this one :


foreach($csv as $car){
$type = $car[0];
$used += ($type == "Used")?1:0;
$new += ($type == "New")?1:0;
}