The following code echos "Null" but how is this possible? The fopen
returns not false (i.e. a valid file handler) but the fgetcsv
returns NULL which means invalid file handler given. I don't understand this.
if ($fh = fopen("2014_01.csv", 'r') !== FALSE) {
if ($test = fgetcsv($fh, 0, ';') == NULL)
echo "Null";
fclose($fh);
} else
echo "fh error";
Take a look at the PHP operators precedence. The comparison (==
) has higher precedence than the assignment (=
), that's why it evaluates like this:
if ($fh = (fopen() !== FALSE)) {
if ($test = (fgetcsv() == NULL))
And this is not what you want. Put parenthesis around the assignments:
if (($fh = fopen("2014_01.csv", 'r')) !== FALSE) {
if (($test = fgetcsv($fh, 0, ';')) == NULL)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加