Arpita Chopra Arpita Chopra - 4 years ago 106
PHP Question

fetch index of row of csv file using php

I want to fetch index of row of csv file in php but i'm not able to use

indexOf
in php.

<?php
$value = $building."".$floor;
$val = $value.".".csv;
$file = fopen("csv/$val","r");
$chk=0;
$x1chk=0;
$x2chk=0;
$y1chk=0;
$y2chk=0;
while(!feof($file)) {
$content = fgetcsv($file);
$index = indexOf($content);
$count1 = count($content);
}
?>

Answer Source

As you are using a while loop you can initialize a variable counter = 0 outside the loop and inside the loop you can increment it e.g

$counter=0;
while(!feof($file)){
    $content = fgetcsv($file);
    $counter++;
}

Hope it helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download