调用函数未正确检查数组中是否存在该值?
$user->setError("h", "h", "error");
$user->setError("h2", "h", "error");`
功能:
public function setError($title, $msg, $type) {
if(!isset($_SESSION['messages'])) {
$_SESSION['messages'][] = array("title" => $title, "message" => $msg, "type" => $type);
} else {
$key = array_search($title, $_SESSION['messages']);
if($_SESSION['messages'][$key]['title'] !== $title)
$_SESSION['messages'][] = array("title" => $title, "message" => $msg, "type" => $type);
}
}
出于某种原因,一直到阵列添加,我不知道我做错了。
在此先感谢
变化'array_search($标题,$ _SESSION [ '消息']);'到'array_search($标题,array_column($ _ SESSION [ '消息'] ,'title'));' –