检查返回false的数组的值?
问题描述:
我需要检查2个不同数组中的2个值是否相同。 我目前从MySQL获取一个值,另一个来自Facebook API。检查返回false的数组的值?
$UserHomeTown[1]
是用户的位置和$city_Value[1]
是朋友的位置,但是当我尝试和检查这些之间的值我总是得到错误。
通过回以筛选测试的说法,这就是我得到
if (Lancashire === United Kingdom) False
if (Lancashire === Lancashire) False
我都试过!=,!==,===,==,仍然我得到的是假的,
这里是我的代码从Facebook
$userFriend_profile = $facebook->api('/me/friends?fields=name,location');
$total = count($userFriend_profile['data']);
for ($i = 0; $i < $total;)
{
if(isset($userFriend_profile['data'][$i]['location']['name']))
{
$city_Value = explode(',',trim($userFriend_profile['data'][$i]['location']['name']));
if ($city_Value[0] != $UserHomeTown[0]) { // This on works
if (isset($city_Value[1])) {
echo "if ($UserHomeTown[1] === $city_Value[1])";
if ($UserHomeTown[1] === $city_Value[1]){
echo "<br> True<br><br>";
} else {
echo "<br> False<br><br>";
}
}
}
}
$i = $i + 1;
}
答
虽然我没有看到任何错误代码获取信息,尝试
if ($UserHomeTown[1] == $city_Value[1])
代替if ($UserHomeTown[1] === $city_Value[1])
答
阵列$city_Value[1]
路过其中未在输出表示实际值前面的空间,但被返回false
if语句是看到"Lancashire" == " Lancashire"