add to array if it isn't there already

前端 未结 14 1294
北海茫月
北海茫月 2020-12-13 07:53

How do I add elements to an array only if they aren\'t in there already? I have the following:

$a=array();
// organize the array
foreach($array as $k=>$v)         


        
14条回答
  •  悲哀的现实
    2020-12-13 08:49

    Try this code, I got it from here

    $input = Array(1,2,3,1,2,3,4,5,6);
    $input = array_map("unserialize", array_unique(array_map("serialize", $input)));
    

提交回复
热议问题