уникальный массив не работает нормально на строке тега

Я боролся за то, чтобы отобразить отдельный тег, который я сохранил в базе данных. В моей базе данных я сохранил некоторые теги, когда я попытался отобразить его обратно, я использовал массив уникальный, но он не работал. см. ниже пример базы данных

item     | tag
---------|---------------
code 1   | html,php,css
code 2   | jquery,xml,js
code 3   | php,python,xhtml
code 4   | css

Теперь, когда я выберу тег из моей таблицы, я получу ниже

<?php
$tags = 'html,php,css
jquery,xml,js
php,python,xhtml
css';
//Here i

$string = explode(',', $tags);
foreach($string as $linetag){
//echo $linetag;
$result = array_unique($linetag);
echo $resul;
}
?>

Но приведенный выше код не работает. Я хочу отображать уникальные теги и удалять дубликаты, как показано ниже

html,
php,
css
jquery,
xml,
js
python,
xhtml

-2

Решение

Попробуйте это для тега href anchor

 $tags = 'html,php,css,jquery,xml,js,php,python,xhtml,css';

$string = explode(',', $tags);
$result = array_unique($string);

foreach($result as $d){

echo ' '."<a href=''> $d</a>";

}
0

Другие решения

$tags = 'html,php,css,jquery,xml,js,php,python,xhtml,css'; //string
$string = explode(',', $tags); //convert string into array by using php standard function
echo "<pre>"; print_r($string); // print array
$string1 = array_unique($string); //Removes duplicate values from an array
echo "<pre>"; print_r($string1); //print unique array
// if you want string again of this array use implode function
$unique_tags = implode(',', $string1);
echo $unique_tags;
0

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector