|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-06-19 14:32 UTC] thomas at landauer dot at
Description:
------------
When a data value is `false`, fputcsv() just omits it - instead of exporting it as `0`.
Test script:
---------------
$data = array('name'=>'foo', 'active'=>false);
$f = fopen('php://memory', 'r+');
fputcsv($f, $data);
rewind($f);
echo stream_get_contents($f);
Expected result:
----------------
foo,0
Actual result:
--------------
foo,
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 17:00:02 2025 UTC |
This doesn't sound like a bug, it is possible for false to be interpreted as null rather than 0. You can probably do something like this to get 0(adjust according to your actual code): Script: --------------------- $data = array('name'=>'foo', 'active'=> (int)false); $f = fopen('php://memory', 'r+'); fputcsv($f, $data); rewind($f); echo stream_get_contents($f); Result: -------------------------- foo,0