我想知道是否有办法简化此代码? 我尝试过很多东西,但不简单......
谢谢!
$pos = strpos_arr(cPR("description"), $arraylist_3);
if ($pos === false) {
} else {
$error = true;
$error_text.= $error_3;
}
$pos = strpos_arr(cPR("description"), $arraylist_4);
if ($pos === false) {
} else {
$error = true;
$error_text.= $error_4;
}
$pos = strpos_arr(cP("description"), $arraylist_5);
if ($pos === false) {
} else {
$error = true;
$error_text.= $error_5;
}
答案 0 :(得分:0)
做一个foreach循环吗?
$arrays = [
$arraylist_3 => $error_3,
$arraylist_4 => $error_4,
$arraylist_5 => $error_5
];
foreach ( $arrays as $arr => $error_msg )
{
$pos = strpos_arr(cPR("description"), $arr);
if ($pos !== false) {
$error = true;
$error_text .= $error_msg;
}
}