rgb192
asked on
fputcsv make empty column
fputcsv($fp,array(NULL,NUL
NULL makes empty column
could I say
$variable=NULL to have empty column
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Code snippet outputs:
HERE IS VAR BETWEEN PIPES||NULL EMPTY
PHP is a loosely typed language, meaning that it converts data types to what it "thinks" you need. So if you add integer 3 to float 0.5. PHP will give you float 3.5 for the answer. With strings, the NULL value is equal to an empty string of zero length.
Note that I said "equal" and not "identical" -- strict comparisons, made with the triple equal sign find that NULL is not the same as an empty string of zero length. But if you want an empty column in your output, you can use NULL or "" and either of those will do nicely.
HERE IS VAR BETWEEN PIPES||NULL EMPTY
PHP is a loosely typed language, meaning that it converts data types to what it "thinks" you need. So if you add integer 3 to float 0.5. PHP will give you float 3.5 for the answer. With strings, the NULL value is equal to an empty string of zero length.
Note that I said "equal" and not "identical" -- strict comparisons, made with the triple equal sign find that NULL is not the same as an empty string of zero length. But if you want an empty column in your output, you can use NULL or "" and either of those will do nicely.
<?php // RAY_temp_rgb192.php
error_reporting(E_ALL);
$var=NULL;
echo 'HERE IS VAR BETWEEN PIPES' . "|$var|";
var_dump($var);
if ($var == '') echo 'EMPTY';
if ($var === '') echo '===EMPTY';
ASKER
but is there any way to
define $variable
before this statement
fputcsv($fp,array(NULL,NUL L,NULL,$va riable));
to make it a blank (empty) column
define $variable
before this statement
fputcsv($fp,array(NULL,NUL
to make it a blank (empty) column
$variable = '';
fputcsv($fp,array(NULL,NUL L,NULL,$va riable));
should do the trick
fputcsv($fp,array(NULL,NUL
should do the trick
Regarding this:
but is there any way to
define $variable
before this statement
fputcsv($fp,array(NULL,NUL L,NULL,$va riable));
Try this:
fputcsv($fp,array(NULL,NUL L,NULL,NUL L));
There is no need for any variable -- if what you really want is NULL, use NULL. It will make the code easier to read since the intent will be clear, and not obscured behind a variable name.
HTH, ~Ray
but is there any way to
define $variable
before this statement
fputcsv($fp,array(NULL,NUL
Try this:
fputcsv($fp,array(NULL,NUL
There is no need for any variable -- if what you really want is NULL, use NULL. It will make the code easier to read since the intent will be clear, and not obscured behind a variable name.
HTH, ~Ray
ASKER
I wanted to set to NULL
but
'' works
but
'' works
?
fputcsv($fp,array('NULL','NULL','NULL','NULL'));
@NerdsOfTech... Come closer to the warm coffee... NULL (the predefined PHP constant) is not the same as 'NULL' (the quoted character string).
http://php.net/manual/en/language.types.null.php
;-)
Best to all, ~Ray
http://php.net/manual/en/language.types.null.php
;-)
Best to all, ~Ray
LOL I know that's why I was wondering why rgb192 wants null if '' is the same, yes (that is in regards to php)? Please enlighten us Ray -- as you have more experience -- is NULL and '' the same in PHP?
Nevermind NULL is NULL and '' is EMPTY :)
NULL and '' are constructively the same when writing data strings. The advantage of using NULL versus '' is that you can easily see and understand that you deliberately wanted a NULL (empty) string. I've used both and have come to prefer the more easily readable word NULL. In a class of several hundred lines, you will see that it stands out better when you are trying to read the code.
Sidebar note... zero is also empty() which is sometimes useful if you cast integer values and use them as DB keys. MySQL has no zero in its sequence of auto_increment keys.
Bets to all, ~Ray
Bets to all, ~Ray
That's awesome info Ray! I understand and agree. Thanks again!
Open in new window