从数组中更新或删除单词,然后将数组内爆并将新值保存到数据库字段中。
//Remove all instances of $value from $array
function array_remove($array, $value) {
return array_filter($array, function ($e) use ($value) {
return $e != $value;
});
}
// Add only unique values
function array_add($array, $value) {
if (!in_array($value, $array))
$array[] = $value;
return $array;
}
$text = "name,fname,lname,class,age" ;
$newtext = explode(",", $text) ;
$newtext = array_remove($newtext, 'lname'); // Remove lname
$newtext = array_add($newtext, 'mail'); // Add mail
$newtext = array_add($newtext, 'class'); // Won't add it again
$newtext = implode(',', $newtext); // name,fname,class,age,mail