是否有可能转换null为stringPHP?
例如,
$string = null;
Run Code Online (Sandbox Code Playgroud)
至
$string = "null";
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?
if ($string === null) {
$string = 'null';
}
Run Code Online (Sandbox Code Playgroud)
在想什么更短......
if ($string === null) $string = 'null';
Run Code Online (Sandbox Code Playgroud)
您还可以使用条件运算符:
$string = ($string === null) ? 'null' : $string;
Run Code Online (Sandbox Code Playgroud)
你的来电.
小智 5
在PHP 7中,您可以使用Null合并运算符 ??
$string = $string ?? 'null';
Run Code Online (Sandbox Code Playgroud)