PHP 同时 + if 语句问题
我有这个:
while($row = mysql_fetch_array($result)) {
$number1=$row["number"];
if (!empty($number1)) {
// A few things happen here using if statements aswell but its fine
}
if (empty($number1)) {
// A few things happen here using if statements aswell but its fine
}
}
由于某种原因,数据在那里但不起作用。根本不会出现任何错误,然后它会重定向到我希望它重定向到的页面。
I have this:
while($row = mysql_fetch_array($result)) {
$number1=$row["number"];
if (!empty($number1)) {
// A few things happen here using if statements aswell but its fine
}
if (empty($number1)) {
// A few things happen here using if statements aswell but its fine
}
}
For some reason, the data is there but it isn't working. No errors emerge at all and it then redirects to the page I want it to redirect to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否知道
empty
的作用比您想象的要多思考?例如,
empty("0")
为true
。使用 if (strlen($number1) > 0) 可能会更好。
Are you aware that
empty
does more than you might think?For example,
empty("0")
istrue
.You might be better off with
if (strlen($number1) > 0)
.也许空会在您可能期望为 true 的项目上返回 false...(例如 0)。请参阅:http://php.net/manual/en/function.empty.php
Maybe empty is returning false on an item that you might expect to be true... (for example 0). See: http://php.net/manual/en/function.empty.php
您应该检查(打印出来或其他什么)
$number1
是否包含您期望的内容?empty($number1)
的行为是否符合您的预期?You should check (print out or whatever)
$number1
contain what you expect?empty($number1)
behave as you expect?