5
A
回答
7
我失去了一些東西在這裏?
if ($string === null) {
$string = 'null';
}
在想什麼......短
if ($string === null) $string = 'null';
您還可以使用the conditional operator :
$string = ($string === null) ? 'null' : $string;
您的電話。
0
if ($string == null)
{
$string = "null";
}
9
var_export可以表示可解析字符串中的任何變量。
-1
它有最好的解決辦法:
$var = null;
$stringNull = json_encode($var);
$null = json_decode($stringNull, true);
var_dump($stringNull);
var_dump($null);
+0
太棒了!謝謝:-) – laukok 2012-04-02 00:16:08
+1
似乎是最慢和過度複雜 – 2015-01-22 15:46:38
1
雖然不是很優雅或清晰,你也可以做以下
is_null($string) && $string = 'null'; // assignment, not a '==' comparison
// $string is 'null'
或
$string = is_null($string) ? gettype($string) : $string;
// $string is 'NULL'
注:var_export($string, true)
(中提到其他回覆)返回'NULL'
相關問題
- 1. mssql_bind將空字符串轉換爲NULL
- 2. 將`NULL`轉換爲字符串(空或者字面上`NULL`)
- 3. 將NULL轉換爲空字符串 - 將字符串轉換爲uniqueidentifier時轉換失敗
- 4. Zend Framework將NULL字符串轉換爲MySql的實際NULL值
- 5. 將字符串轉換爲字符串
- 6. 將字符串轉換爲字符串
- 7. 將字符串轉換爲字符串
- 8. 將字符串轉換爲int,int轉換爲字符串
- 9. 將字符串轉換爲「_」
- 10. 將字符串轉換爲
- 11. 將字符串轉換爲?
- 12. 簡單的方法將字符串轉換爲數字或null?
- 13. 如何將NULL的文本字符串轉換爲數字?
- 14. 將NULL字節的C字符串轉換爲char數組
- 15. 將轉換器映射字符串轉換爲字符串
- 16. 將字符串轉換爲字符ascii
- 17. Java - 將字符串轉換爲字符[]
- 18. C++ - 將字符串轉換爲字符
- 19. 將字符*轉換爲字符串
- 20. 將字符串轉換爲字符
- 21. 將字符串轉換爲const *字符
- 22. 將字符[]轉換爲字符串
- 23. InfixToPostfix將字符轉換爲字符串
- 24. 將字符串轉換爲字符
- 25. 將char字符串轉換爲字符
- 26. 將字符串轉換爲字符
- 27. 將textField轉換爲字符串並將字符串轉換爲textField
- 28. JsonModel NSString將null轉換爲空字符串
- 29. 將字符串轉換爲返回null的日期
- 30. Objective-c將字符串轉換爲雙倍結果null
不,你沒有。我只是認爲如果條件不成立,可能會有一種方法...猜不到:-) – laukok 2012-03-28 18:33:33
使用'if'有什麼問題? – 2012-03-28 18:34:07
沒問題。思考的東西更短...像'(字符串)null' ... – laukok 2012-03-28 19:16:27