我正在尝试比较两个字符串。当我打印它们时,它们看起来是相同的,但是当我使用“==”运算符进行比较时,它返回false。例如,在我的数据库上运行以下代码时,它输出类似于“显然,Apple不等于Apple”的内容。原因是什么?
if ($this->data['list_text']) { // The user has entered into textarea
$list = nl2br($this->data['list_text']);
$list_array = explode('<br />', $list);
$ranking = 1;
$company_array = $this->CompanyList->CompanyRanking->Company->find('list', null);
// This is the comparison bit
foreach ($list_array as $key => $value) {
$companyId = null;
foreach ($company_array as $key2 => $value2) {
if ($value2 != $value) {
echo 'APPARENTLY ' . $value2 . ' does not equal ' . $value;
} else {
$companyId = $key2;
break;
}
}
$this->data['CompanyRanking'][$ranking]['ranking'] = $ranking;
$this->data['CompanyRanking'][$ranking]['company_id'] = $companyId;
$ranking++;
}
}
===
)。 - Peter Mortensen