您好我正在尝试验证数组并从文本框中插入数据。
但我不想插入重复的值。
e.g
######### 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
任何人都可以帮我这个吗?
我尝试了一些方法,但我无法做到。
答案 0 :(得分:0)
$textbox = 'Carlos,Jose,Carlos,Lauro,Marcos';
$textarea = array();
$list = explode(',' , $textbox);
foreach(array_unique($list) as $key){
if(!in_array($key , $textarea)){
$textarea[] = $key;
}
}