Q:

Php function returns the same with different parameters

There is a csv file with data about the weather.  I am making something which calculates the mean of a column per station from that csv file.  That column is passed in the parameters of the function. 
First of all I have this list of id's from the weatherstation.  The values I add to the list are arrays which contains the sum and count of a datatype. 
$station_id = array("960350", "960870", "961090", "961790", "962210", "962370", "962950", "963230",
        "965810", "966330", "966850", "967430", "967470", "967490", "967810",
        "968050", "968810", "969330", "969350", "969870", "970140", "970480",
        "970720", "971200", "971260", "971460", "971800", "971925", "972300",
        "972400", "972600", "973000", "973400", "974280", "974300", "975600",
        "977240", "977900", "978100", "979000");
        //Every item in the array becomes a key, with an array as a value. 
        //StationID => [sum, count]
$station_id = array_fill_keys($station_id, []);

The function down here reads the lines of the csv file, adds the value if it is there, adds one to the counter, calculates the mean and prints it per station.  Finally it clears the values of the array station_id. 
function calc_average($to_be_calc){
            global $station_id; //array with station_id's as keys.  The value is the sum and the count. ( 0=sum , 1+count)
            global $file; //The csv file. 
            while (($line = fgetcsv($file)) ! == FALSE) {
                list($STN, $DATE, $TIME, $TEMP, $DEWP, $STP, $SLP, $VISIB, $WDSP, $PRCP, $SNDP, $FRSHTT, $CLDC, $WNDDIR) = $line;

                if (is_numeric($STN)) {
                    $station_id[$STN][0] += $$to_be_calc;   //Sums the values of for example temp
                    $station_id[$STN][1] += 1;              //Adds one to the counter of the station. 
                }
            }

            foreach ($station_id as $key => $value) {
                if ($value[1] > 0) {
                    //Calculate average
                    $average = number_format($value[0] / $value[1], 1, ',', ' ');
                    //print average per station
                    echo "Average of station $key: $average</br>";
                }
            }
            foreach ($station_id as $key => $value){
                unset($key);
            }
        }

The problem I have now is that when I call it like this:
        calc_average("TEMP");
        echo "<br>";
        calc_average("CLDC");

It prints the averages of the temperature per station twice.  Instead of first TEMP, then CLDC.  Like this.  If I first call calc_average with CLDC as parameter it only does with CLDC.  
I have no idea how this is possible.  Therefore, my question is how to fix this. 

SOLUTION
I didn't rewind the pointer at the end of my function.  All I had to do was add rewind($file); to my function.  I works great now.  Thanks

A:

Placing my answer from the comments in an actual answer:
I am assuming $file is a file pointer obtained using something like fopen().  If so, are you resetting the pointer back to the beginning of the file?  If not, $line = fgetcsv($file) will always return false at the start of the second calc_average() call. 