Hello I am trying to validate an array and insert into it from a textbox.
but I do not want to insert duplicate values.
eg
######### Inserting first name #####
$textbox = 'Jose,';
$textarea = Array();
$list = explode(',', $list, -1);
foreach(array_unique($list) as $key){
if ($textbox != $key){
insert (Jose,)into textarea;
}
}
(exit)
########### second name ######
$textbox = 'Carlos,';
$textarea = Array('Jose,');
$list = explode(',' $list, -1);
foreach(array_unique($list) as $key){
if($textbox != $key){
insert (Carlos,) into textarea;
}
}
(exit)
########### 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;
}
}
(exit)
here is my code...
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
anyone could help me with this ?
I have tried a few of ways, but I could not do it.
$textbox = 'Carlos,Jose,Carlos,Lauro,Marcos';
$textarea = array();
$list = explode(',' , $textbox);
foreach(array_unique($list) as $key){
if(!in_array($key , $textarea)){
$textarea[] = $key;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.