Is it possible to convert null
to string
with php?
For instance,
$string = null;
to
$string = "null";
Am I missing something here?
if ($string === null) {
$string = 'null';
}
was thinking something shorter...
You can do it in one line, and omit the braces:
if ($string === null) $string = 'null';
You can also use the conditional operator:
$string = ($string === null) ? 'null' : $string;
Your call.
var_export can represent any variable in parseable string.
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