Php 如何从字符串中删除分解的逗号分隔数组中的重复值? $NoteKey=“,”; (循环)如果。。。然后{ $NoteKey.=“”; $NoteKey.=$val2; $NoteKey.=“”; $NoteKey.=$val3; $NoteKey.=“”; $NoteKey.=“”; $NoteKey.=“,”; } $NoteKey_trim=trim($NoteKey,“,”); $NoteKey_clean=爆炸(“,”,$NoteKey_trim); $NoteKey_unique=数组_unique($NoteKey_clean);
问题是没有任何输出。。。它一直工作到Php 如何从字符串中删除分解的逗号分隔数组中的重复值? $NoteKey=“,”; (循环)如果。。。然后{ $NoteKey.=“”; $NoteKey.=$val2; $NoteKey.=“”; $NoteKey.=$val3; $NoteKey.=“”; $NoteKey.=“”; $NoteKey.=“,”; } $NoteKey_trim=trim($NoteKey,“,”); $NoteKey_clean=爆炸(“,”,$NoteKey_trim); $NoteKey_unique=数组_unique($NoteKey_clean);,php,arrays,Php,Arrays,问题是没有任何输出。。。它一直工作到$NoteKey\u clean然后没有输出…String[]functions=CommaseOperatedString.split(,”); $NoteKey = ","; (loop) if ... then{ $NoteKey .= "</td><td>"; $NoteKey .= $val2; $NoteKey .= "</td><td>"; $NoteKey .=
$NoteKey\u clean
然后没有输出…String[]functions=CommaseOperatedString.split(,”);
$NoteKey = ",";
(loop) if ... then{
$NoteKey .= "</td><td>";
$NoteKey .= $val2;
$NoteKey .= "</td><td>";
$NoteKey .= $val3;
$NoteKey .= "</td><td>";
$NoteKey .= "</td></tr>";
$NoteKey .= ",";
}
$NoteKey_trim = trim($NoteKey, ",");
$NoteKey_clean = explode(",",$NoteKey_trim);
$NoteKey_unique = array_unique($NoteKey_clean);
List uniqueFunctions=new ArrayList();
for(字符串函数:函数){
如果(!uniqueFunctions.contains(function.trim())){
uniqueFunctions.add(function.trim());
}
}
返回字符串。join(“,”,uniqueFunctions);
不要将html标记放入数组,只需将值放入数组,需要打印时,将值放入标记之间。
$NoteKey_trim = trim($NoteKey, ",");// delete ","
$NoteKey_clean = explode(",",$NoteKey_trim); // $NoteKey_trim don't have ","
//explode can't find ","
$NoteKey_unique = array_unique($NoteKey_clean);
$NoteKey_trim = trim($NoteKey);
if(strpos(",",$NoteKey_trim)!==false){ // $NoteKey_trim has ","
$NoteKey_clean = explode(",",$NoteKey_trim);
$NoteKey_unique = array_unique($NoteKey_clean);
}
String[] functions= commaSeperatedString.split(",");
List<String> uniqueFunctions = new ArrayList<>();
for (String function : functions) {
if ( !uniqueFunctions.contains(function.trim())) {
uniqueFunctions.add(function.trim());
}
}
return String.join(",",uniqueFunctions);