I have a strange problem. I have this piece of code:
$array = array('abc',null,'def',null);
$implode = implode(",", $array);
var_dump($implode);
and the result is:
string 'abc,,def,' (length=9)
Is there any way I can print null as a string? I mean, some thing like this:
string 'abc,null,def,null' (length=17)
Thanks a lot!
EDIT:
Thank you all for your responses. I think they are the same, but developed differently. I was thinking in array_map but I didn't know exactly how to use it. Thanks!
You could use array_walk to go over every item in the array and turn them to string if they are null:
$array = array('abc',null,'def',null);
function x(&$el) {
$el = ($el === null) ? 'null' : $el;
}
array_walk($array, 'x');
$implode = implode(",", $array);
var_dump($implode);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With