开发者

My outrageously simple IF statement is evaluating to false... when it's undeniably true!

if($array[$i]['positiveOrNegative'] == 'p')

This array value is pulled from MySQL DB, from a CHAR(1) column. I've var_dumped both variables and BOTH return string(1) p

I have NO idea in the world why this isn't evaluating correctly, it's honestly blowing m开发者_如何学Cy mind. It does work if I do p == p. Also, strcmp($array[$i]['positiveOrNegative'],p) returns 1 (meaning they are NOT the same). How, on earth, could this be!?

--------UPDATE:

Wait, I must have VarDumped badly.... now my variable is this:

  • $array[$i]['positiveOrNegative']

  • string(4) "p"

AND

  • var_dump(p)
  • string(1) "p"

How is the variable p inside MySQL a string(4) ???

More Updates... Every entry in that column is a string(4), but they are all one letter (n or p). Further, they are string(4)'s even when I insert the letter by hand with PHPMyAdmin...


have you tried printing the array out to screen to see the output?

print_r($array[$i]['positiveOrNegative']);

By doing this you will be able to see the entire contents of the array and any oddities should stick out pretty clearly.

The reason I mention this is because it may not matter exactly how the database is treating it, as long as it is persisting a value you can use.

Therefore if you check the result of your operation visually to make sure there is nothing odd happening you might be able to format that database output before doing your conditional comparison.


Echo it out and run it through od -c. This will tell you exactly what PHP has in the variable. From there you can scrub the data, and perhaps fix the process that is inserting this malformed data in the first place.

php somescript.php | od -c


If the string really has 4 bytes try doing to following so we can further examine the contents:

print_r(array_map('ord', str_split($array[$i]['positiveOrNegative'])));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜