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
此数组值从CHAR(1)列的MySQL DB中提取。我已经var_dumped两个变量和BOTH返回字符串(1)p
I have NO idea in the world why this isn't evaluating correctly, it's honestly blowing my 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!?
我不知道世界上为什么没有正确评估,这真的让我大吃一惊。如果我做p == p,它确实有效。另外,strcmp($ array [$ i] ['positiveOrNegative'],p)返回1(意味着它们不相同)。究竟怎么样呢!?
--------UPDATE:
Wait, I must have VarDumped badly.... now my variable is this:
等等,我必须有严重的VarDumped ....现在我的变量是这样的:
$array[$i]['positiveOrNegative']
string(4) "p"
AND
- var_dump(p)
- string(1) "p"
How is the variable p inside MySQL a string(4) ???
如何将MySQL中的变量p作为字符串(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...
更多更新...该列中的每个条目都是一个字符串(4),但它们都是一个字母(n或p)。此外,即使我用PHPMyAdmin手工插入字母,它们也是字符串(4)...
3 个解决方案
#1
2
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.
因此,如果您直观地检查操作结果以确保没有发生任何奇怪的事情,则可以在进行条件比较之前格式化该数据库输出。
#2
1
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.
回声并通过od -c运行它。这将告诉您PHP在变量中的确切含义。从那里,您可以清理数据,并可能首先修复插入这种格式错误的数据的过程。
php somescript.php | od -c
#3
0
If the string really has 4 bytes try doing to following so we can further examine the contents:
如果字符串确实有4个字节,请尝试执行以下操作,以便我们可以进一步检查内容:
print_r(array_map('ord', str_split($array[$i]['positiveOrNegative'])));
#1
2
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.
因此,如果您直观地检查操作结果以确保没有发生任何奇怪的事情,则可以在进行条件比较之前格式化该数据库输出。
#2
1
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.
回声并通过od -c运行它。这将告诉您PHP在变量中的确切含义。从那里,您可以清理数据,并可能首先修复插入这种格式错误的数据的过程。
php somescript.php | od -c
#3
0
If the string really has 4 bytes try doing to following so we can further examine the contents:
如果字符串确实有4个字节,请尝试执行以下操作,以便我们可以进一步检查内容:
print_r(array_map('ord', str_split($array[$i]['positiveOrNegative'])));