您好,我正在尝试验证一个数组并从文本框中插入它。
但我不想插入重复的值。
例如
######### Inserting first name #####
$textbox = 'Jose,';
$textarea = Array();
$list = explode(',', $list, -1);
foreach(array_unique($list) as $key){
if ($textbox != $key){
insert (Jose,)into textarea;
}
}
(出口)
########### second name ######
$textbox = 'Carlos,';
$textarea = Array('Jose,');
$list = explode(',' $list, -1);
foreach(array_unique($list) as $key){
if($textbox != $key){
insert (Carlos,) into textarea;
}
}
(出口)
########### third name ######
$textbox = 'Carlos,';
$textarea = Array('Jose,Carlos,');
$list = explode(',' $list, -1);
foreach(array_unique($list) as $key){
if($Carlos != $key){ //$key = Jose
insert (Carlos,) into textarea;
} //next
if($Carlos != $key){ //$key = Carlos
insert (Carlos,) into textarea;
}else{
It exist;
}
}
(出口)
这是我的代码...
foreach ( array_unique($viewer) as $viewermi ){
if ( $userdata['uid'] != $viewermi ){
$objResponse->addAppend('viewerlist', 'value', $userdata['uid'].',');
$objResponse->addAssign('vieadded', 'value', '');
$objResponse->addAssign('vadded', 'innerHTML', $user.' Added');
$objResponse->addScript('$(\'#btViewAdded\').attr(\'disabled\', true)');
}else{
$objResponse->addAssign('vadded', 'innerHTML', '');
$objResponse->addAlert("It uid had been added! ".$viewermi);
$objResponse->addAssign('vieadded', 'value', '');
$objResponse->addScript('$(\'#btViewAdded\').attr(\'disabled\', true)');
} // End If-Else $userdata
} // End foreach Viewers
任何人都可以帮助我吗?
我尝试了几种方法,但我无法做到。