Re: fgetcsv doesn't return an array?

From: Date: Sun, 18 Mar 2012 17:16:49 +0000
Subject: Re: fgetcsv doesn't return an array?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-317108@lists.php.net to get a copy of this message
Tamara Temple wrote:
On Thu, 15 Mar 2012 12:09:53 -0500, Jay Blanchard <jay.blanchard@sigmaphinothing.org> sent:
I thought that fgetcsv returned an array. I can work with it like an array but I get the following warning when using it |Warning: implode(): Invalid arguments passed on line 155
154    $csvCurrentLine = fgetcsv($csvFile, 4096, ',');
155    $currentLine = implode(",", $csvCurrentLine);
| Everything that I have read online indicates that it is because $csvCurrentLine is not declared as an array. Adding a line to the code 153 |$csvCurrentLine = array(); Does not get rid of the warning. The warning isn't interfering with the script working, but it us annoying. Does anyone know the solution?
Just want to clarify something not directly related to the OP's question: This:
153 |$csvCurrentLine = array();
Does not set a *type* for $csvCurrentLine, so if you're next line is this:
154    $csvCurrentLine = fgetcsv($csvFile, 4096, ',');
Any previous assignments are lost; the notion that presetting $csvCurrentLine to an array has no bearing when you then immediately set the same variable to something else. The "type" $csvCurrentLine has after line 154 is entirely dependent on what fgetcsv() is returning, and nothing that happened prior to line 154.
In this case, Jay's attempt to fix the problem was simply wrong. fgetcsv may well not return an array, and the error in this code was simply that situation. If an array is not returned by fgetcsv then there was an error, hence line 155 fails every time you hit the 'EOF' condition. -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk// Firebird - http://www.firebirdsql.org/index.php

« previous php.general (#317108) next »