title: what should I use instead of array_unique in php?
body: <p>I am getting duplicate data in an array and that data is storing in my DB. I am using array_unique to refine the duplicate data but it is not working. Please tell me is there any other way to make data unique and store in DB this way.</p>
  <pre><code>if (preg_match($keywords, $links[$i]-&gt;href)) {
      if (filter_var($links[$i]-&gt;href, FILTER_VALIDATE_URL) !== false) {
          array_push($mainNews, $links[$i]-&gt;href);
      }
  }
      return (array_unique($mainNews));
  </code></pre>
  <p>Error I am getting:</p>
  <blockquote>
  <p>Undefined array key 1 at C:\xampp\htdocs\pacra-crawlers\modules\crawlers\services\MainNewsRepository.php:46</p>
  </blockquote>
  <pre><code>    for ($i = 0; $i &lt; count($mainNewsLinks); $i++) {
          $mainNews = new MainNews();
          $mainNews-&gt;newspaper_id = $this-&gt;newspaperId;
          $mainNews-&gt;sector_id = $sectorId;
          $mainNews-&gt;url = $mainNewsLinks[$i];
          $mainNews-&gt;save();
      }
      return ['status' =&gt; true];
  }
  </code></pre>
  <blockquote>
  <p>C:\xampp\htdocs\pacra-crawlers\modules\crawlers\services\MainNewsRepository.php:46
  Illuminate\Foundation\Bootstrap\HandleExceptions::handleError(&quot;Undefined array key 1&quot;, &quot;C:\xampp\htdocs\pacra-crawlers\modules\crawlers\services\MainNewsRepo
  sitory.php&quot;)</p>
  </blockquote>