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".

    打赏 评论
  • duansanzi5265 2014-12-22 19:33
    print (($myarray['response']['players'][0]['VACBanned'] != 0) ? 'BANNED' : 'NOT BANNED');
    打赏 评论

相关推荐 更多相似问题