我在某处读到 isset()
函数将空字符串视为 TRUE
,因此 isset()
不是一种有效的方法验证 HTML 表单中的文本输入和文本框。
因此您可以使用 empty()
来检查用户是否输入了某些内容。
isset()
函数是否将空字符串视为TRUE
?那我应该在哪些情况下使用
isset()
?我应该总是使用!empty()
来检查是否有东西吗?
例如代替
if(isset($_GET['gender']))...
使用这个
if(!empty($_GET['gender']))...
最佳答案
自由贸易协定:
"isset() checks if a variable has a value including (False, 0 or empty string), but not NULL. Returns TRUE if var exists; FALSE otherwise.
On the other hand the empty() function checks if the variable has an empty value empty string, 0, NULL or False. Returns FALSE if var has a non-empty and non-zero value."
关于php - 我应该在哪里使用 isset() 和 !empty(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1219542/