title: PHP function for returning array with unique indexes
body: <p>I have a simple problem. Lets say I have an array</p>
  
  <p>Array</p>
  
  <pre><code>0   
  product_id  233
  slug    "zotac-geforce-gtx-1070-amp-extreme-edition-8gb-zt-p10700b-10p"
  
  1   
  product_id  227
  slug    "zotac-geforce-gtx-1060-mini-6gb-gddr5-zt-p10600a-10l"
  
  2   
  product_id  233
  slug    "zotac-geforce-gtx-1070-amp-extreme-edition-8gb-zt-p10700b-10p"
  </code></pre>
  
  <p>Now if you see there are two products having same product_id! I don't want that I am trying to get this array filtered from duplicate products</p>
  
  <p>This is what I tried but it doesn't work</p>
  
  <pre><code>$temp_products = array();
      foreach($products as $product)
      {
          if(count($temp_products) &gt; 0)
          {
              foreach($temp_products as $temp_product)
              {
                  if($temp_product['product_id'] != $product['product_id'])
                  {
                      $temp_products[] = $product;
                  }
              }
          }
          else
          {
              $temp_products[] = $product;
          }
      }
  </code></pre>
  
  <p>It returns the same array as the original one. and <code>$products</code> is the main array having the data.</p>