duandao8607 2014-12-22 19:14
浏览 37
已采纳

Boolean - > String(总是相同)

I have this code:

print ($myarray['response']['players'][0]['VACBanned'] ? 'BANNED' : 'NOT BANNED');

Where "VACBanned" is boolean. But it doesn´t matter if it's 'true' or 'false'; it always gives out "NOT BANNED".

var_dump result: Case 1: 'VACBanned' => bool(true) Case 2: 'VACBanned' => bool(false) Both cases show "NOT BANNED"

PIC: http://i.stack.imgur.com/Rk7uv.png http://i.stack.imgur.com/o0i9f.png

  • 写回答

2条回答 默认 最新

  • dsj0312 2014-12-22 21:14
    关注

    You need to turn error checking on—or check your apache error log—and find the bugs in your code.

    For example, your var_dump($myarray); shows an array that doesn't have any keys of 'response'. However, your print statement is:

    print ($myarray['response']['players'][0]['VACBanned'] ? 'BANNED' : 'NOT BANNED');
    

    The array expression can never find anything, as there's no key of "response". So it will (a) be throwing an error "Undefined index: response", and (b) always evaluate to false, and therefore always say "NOT BANNED".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧