I've a function that gets a `.csv` file from parameter and a `myrownumber` (a number indicating a row of the .csv) of this array.

This returns the content of the line number `myrownumber` of the csv file.

```
private function readASpecificRow($filePath, $myrownumber)
{
    $rowImLookingFor = array();
    $f = fopen($filePath, "r");
    $i = 0;
    while (($line = fgetcsv($f)) !== false)
    {
        $i ++;
        foreach ($line as $cell)
        {
            if ($i == $myrownumber)
            {
                array_push($rowImLookingFor, $cell);
            }
        }
    }
    fclose($f);

    return($rowImLookingFor);
}

```

This is very innefficent as I've to iterate all the file until I find the row I'm looking for.

**Is there any other way to read directly the row number `myrownumber` of the `csv` file?**

PS: I know there are a lot of solutions with will like to keep using `fgetcsv` because on the cells are some line breaks and with `fgetscsv` I keep the control of it. If i use `file` or whatever, the number of lines are different from the real number of lines of the csv due to the line breaks inside of some cells.

Thanks in advance.
['https://Stackoverflow.com/questions/43606911', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/742269/']
I know that this doesn't provide you with a different solution but it could help with the assumed inefficiency.

I'd personally refactor the function to look more like this:

```
private function readASpecificRow($filePath, $myrownumber)
{
    $f = fopen($filePath, "r");
    $i = 0;
    $myrownumber = (int) $myrownumber; // ensure it's actually a number.
    while (($line = fgetcsv($f)) !== false)
    {
        if (++$i < $myrownumber) continue;
        fclose($f);
        return $line;
    }
    return false; // if the specified line wasn't there return false
}

```

It should be a bit faster.
You can use `file()` to get file by lines, than use `str_getcsv` to parse specific line to CSV.