title: PHP in_array function does not work properly
body: <p>I have this code that tries to do selection on every new element to put into an array (<code>$desArray</code>). It is hoped to not put an element that has the same value as one of the existing elements in the array.</p>
  
  <p>The checking job is supposed to be done by <code>in_array</code> function, which checks if there already is the same title in <code>$rss_array</code>. So the <code>array_push</code> will only be done with the unique ones.</p>
  
  <pre><code>&lt;?php
  
  /* GOOGLE */
  
  function cURL_google($url, $ref, $p) {
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  curl_setopt($ch, CURLOPT_REFERER, $ref);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  if ($p) {
      curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
  }
  $result = curl_exec($ch);
  curl_close($ch);
  if ($result) {
      return $result;
  } else {
      return '';
  }
  }
  
  if (isset($_GET['keyword'])) {
  $keyword_google = $_GET['keyword'];
  } else {
  echo 'Wrong!';
  }
  
  $cseNumber = 'AAAAA';
  $key = 'AAAAAP';
  $rss_array = array();
  $desArray = array();
  
  function _json_decode($file) {
      if (get_magic_quotes_gpc()) {
      $file = stripslashes($file);
      }
      return json_decode($file);
  }
  $file = cURL_google('https://www.googleapis.com/customsearch/v1?key=' . $key . '&amp;cx=' .             $cseNumber . '&amp;q=' . $keyword_google . '&amp;siteSearchFilter=i&amp;alt=json&amp;start=1&amp;num=3', 'https://www.googleapis.com/customsearch/v1?key=' . $key . '&amp;cx=' . $cseNumber . '&amp;q=' . $keyword_google . '&amp;siteSearchFilter=i&amp;alt=json&amp;start=1&amp;num=3', null); // . removed from here
  $feed = _json_decode($file, true);
  foreach ($feed-&gt;items as $item) {
  $rss_item = array(
      'kind' =&gt; $item-&gt;kind,
      'Title' =&gt; $item-&gt;title,
      'Url' =&gt; $item-&gt;link,
      'Description' =&gt; $item-&gt;snippet,
      'formattedUrl' =&gt; $item-&gt;formattedUrl,
  );
  array_push($desArray, $item-&gt;snippet);
  array_push($rss_array, $rss_item);
  }
  
  /* BING */
  if (isset($_GET['keyword'])) {
  $rawkeyword = '%27' . $_GET['keyword'] . '%27';
  $keyword = str_replace(' ', '%27', $rawkeyword);
  //echo $keyword . '&lt;br&gt;';
  } else {
  echo 'Wrong!';
  }
  
  $key_bing = 'AAAAAA'; 
  $root = 'https://api.datamarket.azure.com/Bing/Search/';
  $search = $root . 'Web?';
  $req = $search . 'Query=' . $keyword . '&amp;$top=3&amp;$format=json';
  
  $ch = curl_init($req);
  curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch, CURLOPT_USERPWD, $key . ":" . $key_bing);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  $resp = curl_exec($ch);
  $json = json_decode($resp);
  
  foreach ($json-&gt;d-&gt;results as $item) {
  $rss_item = array(
      'Title' =&gt; $item-&gt;Title,
      'Description' =&gt; $item-&gt;Description,
      'DisplayUrl' =&gt; $item-&gt;DisplayUrl,
      'Url' =&gt; $item-&gt;Url,
  );
  if (in_array($rss_item[$item-&gt;Title], $rss_array, TRUE)) {
      return false;
  } else {
      array_push($desArray, $item-&gt;Description);
      array_push($rss_array, $rss_item);
  }
  }
  
  /* FREE */
  if (isset($_GET['keyword'])) {
  $rawkeyword = $_GET['keyword'];
  $keyword = str_replace(' ', '%20', $rawkeyword);
  echo $keyword . '&lt;br&gt;';
  } else {
  echo 'Wrong!';
  }
  $rootkiri = 'http://www.faroo.com/api?q=';
  $key_free = '&amp;key=AAAAAA';
  $rootkanan = '&amp;start=1&amp;length=3&amp;l=en&amp;src=web&amp;f=json';
  $req = $rootkiri . $keyword . $rootkanan . $key_free;
  
  $ch_free = curl_init($req);
  curl_setopt($ch_free, CURLOPT_TIMEOUT, 30);
  curl_setopt($ch_free, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
  curl_setopt($ch_free, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch_free, CURLOPT_SSL_VERIFYPEER, false);
  
  $resp_free = curl_exec($ch_free);
  $json_free = json_decode($resp_free);
  foreach ($json_free-&gt;results as $item) {
  if (isset($item-&gt;kwic)) {
      $rss_item = array(
          'Title' =&gt; $item-&gt;title,
          'Description' =&gt; $item-&gt;kwic,
          'Url' =&gt; $item-&gt;url,
      );
      if (in_array($rss_item[$item-&gt;title], $rss_array, TRUE)) {
          return false;
      } else {
          array_push($desArray, $item-&gt;kwic);
      }
  } else {
      return false;
  }
  if (in_array($rss_item[$item-&gt;title], $rss_array, TRUE)) {
      return false;
  } else {
      array_push($rss_array, $rss_item);
  }
  }
  
  /* DISPLAYING RESULT */
  for ($i = 0; $i &lt; count($desArray); $i++) {
      echo '&lt;p&gt;'
      . '&lt;a href="' . $rss_array[$i]['Url'] . '" onclick="return false;"&gt;'
      . '&lt;img src="images/positif.png" title="rate this positive" onclick="positif(this);"&gt;'
      . '&lt;img src="images/negatif.png" title="rate this negative" onclick="negatif(this);"&gt;'
      . $rss_array[$i]['Title']
      . '&lt;/a&gt;'
      . '&lt;a href="' . $rss_array [$i]['Url'] . '" target="_blank"&gt;'
      . '&lt;img src="images/open_new_tab.jpg" title="open in new tab"&gt;'
      . '&lt;/a&gt;'
      . '&lt;br/&gt;'
      . '&lt;span class="deskripsi"&gt;' . $rss_array [$i]['Description'] . '&lt;/span&gt;'
      . '&lt;hr/&gt;'
      . '&lt;/p&gt;';
  }
  ?&gt;
  </code></pre>
  
  <p>What I'm asking is the <code>in_array</code> thing,
  It doesn't work and gives me this:
  <code>Notice: Undefined index:</code> (followed by the rss_array[title], repeatedly)
  Then the results displayed, but the duplicates keep showing up.</p>
  
  <p>I tried to do this:</p>
  
  <pre><code>if (in_array($item-&gt;title, $rss_array, TRUE)) {
  </code></pre>
  
  <p>It dismisses the notice thing, but still doesn't dismiss the duplicates.
  For record, these Google, Bing and Free codes worked very well separately. But when I try to unite the results by removing the duplicates, this "stuckness" happens.
  How do I solve this?
  Thank you.. :)</p>