php、mysql、数组 - if( x == 0 ) { }
我有以下代码
while($row = $usafisRSP->fetch_assoc()) { $hidden_keys = array('Applicantid', 'unique_num', 'regs_time' ....); $hidden_fields = array_intersect_key($row, array_fill_keys($hidden_keys, NULL)); $hidden_values = array(); foreach ($hidden_fields as $key => $value) { // fill the values array using the values from fields array $hidden_values[$value] = "$key = ".base64_decode($value)."
"; if(base64_decode($value)== 0) { $hidden_values[$value] = ""; } echo $hidden_values[$value];
问题是关于“if($hidden_values[$value] == 0)”...基本上我想不显示/回显 $hidden_values[$value] 如果 $value 的值为 0有时候$value是0或者一些像(23 avenue)这样的词。
I have the following code
while($row = $usafisRSP->fetch_assoc()) { $hidden_keys = array('Applicantid', 'unique_num', 'regs_time' ....); $hidden_fields = array_intersect_key($row, array_fill_keys($hidden_keys, NULL)); $hidden_values = array(); foreach ($hidden_fields as $key => $value) { // fill the values array using the values from fields array $hidden_values[$value] = "$key = ".base64_decode($value)."
"; if(base64_decode($value)== 0) { $hidden_values[$value] = ""; } echo $hidden_values[$value];
The question is about "if($hidden_values[$value] == 0)" ... Basically I want to do not display/echo the $hidden_values[$value] if it's value of $value is 0. Sometimes $value is 0 or some words like (23 avenue).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您在 PHP 类型比较和相等方面遇到了三个问题:
if(base64_decode($value)== 0)
可能总是解析为 true,即使已解码$value
是“Adam”
。if(base64_decode($value ) === 0)
如果解码后的$value
为"0"
甚至无法工作。另一个问题是,base64_decode 可能会在错误时返回 false,再次未能通过严格的相等性检查。"0"
除外)始终松散地等于 true。因此,这是您的案例真正需要的唯一比较。我认为这就是你想要的,替换最后 5 行......
I think you ran into three catches with PHP type comparisons and equalities:
if(base64_decode($value)== 0)
will likely always resolve to true, even if decoded$value
is"Adam"
.if(base64_decode($value) === 0)
wouldn't even work if decoded$value
is"0"
. Another catch is base64_decode may return false on errors, again failing this strict equality check."0"
) will always loosely equal true. So this is the only comparison you really need for your case.I think this is what you want, replacing the last 5 lines...
这是您要找的吗?
Is this what you're looking for?