H
H
hdtor2016-04-10 17:23:13
PHP
hdtor, 2016-04-10 17:23:13

How to remove duplicates?

There is such a code, it displays the latest tags from the site's articles.

$result = $mysqli->query("SELECT * FROM tags LIMIT 5");
            
              while($row = $result->fetch_array()) {
              
                $pole = explode(',', $row['name']);
                $i = 0;
     
              foreach($pole as $word){
          
              $word = trim($word);
          
              if($word){
                echo "<a href=\"#\">" . $word . "</a>";
              $i++;
              }
               }
                      }

The only question is how to remove duplicates when outputting? Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
X
xmoonlight, 2016-04-10
@xmoonlight

php.net/manual/en/function.array-unique.php
$pole=array_unique($pole);

T
trevoga_su, 2016-04-10
@trevoga_su

distinct dig

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question