title: Removing duplicate values within a comma separated list in PHP
body: <p>How can I remove duplicate values within a comma separated list in PHP?</p>
  
  <p>I have 2 versions of a customer questionnaire - one is more detailed than the other - and in one they are asked the items they like and in the other they are asked to specify the items they like in ranked order. In this particular example, one of the columns ('items_like') may contain several values in a comma separated list. There are two other scenarios where each of the columns may contain several values in a comma separated list. </p>
  
  <p>In order to display a list of all the items a customer likes, I am concatenating the 4 columns when the information is fetched from the db. How can I remove any duplicate values from the combined comma separated list in? I'd prefer doing this in PHP than Javascript</p>
  
  <pre><code>try {  
  $stmt = $conn-&gt;prepare("SELECT * FROM customer_info WHERE user_id = :user_id"); 
  $stmt-&gt;bindValue(':user_id', $user_id); 
  $stmt-&gt;execute();
  }catch(PDOException $e) {echo $e-&gt;getMessage();}
  $row = $stmt-&gt;fetch();
  $search = array('_', ',', 'Null');
  $replace = array(' ', ', ', '');
  $rows = str_replace($search, $replace, $row);
  
  $merged_likes = $rows['items_like']. ",  " . $rows['first_like']. ",  " .     $rows['second_like']. ",  " .  $rows['third_like'];
  echo $merged_likes; 
  </code></pre>