php - Remove duplicate values from Array -
i can not "remove" double values from array if use function array_unique!
<?php $tags_array = array() ; $query_tags = $mysql->query("select words kw users ") ; /**** * * query return array([1] => php,asp,net [2] => ruby,jquery,php,asp_net [3] => php,asp,visualbasic,c# [4] => [5] =>) * *****/ while($fetch_tags = $mysql->fetch($query_tags)) { foreach(explode(',',$fetch_tags['kw']) $kw => $value) { if(empty($value)) ; else { $value = ucwords(strtolower($value)) ; $tags_array[] = $value ; } } } $tags_array = array_values(array_unique($tags_array, sort_string)) ; print_r($tags_array) ; /****** * * print_r show somethings array([1] => asp [2] => php [3] => php [4] => ruby [5] => jquery [6] => php [7] => asp_net [8] = >c# [9] => asp) * * it's example show situation *****/ ?>
make sure returned values in fact not unique. example
$foo = array("php","php","php","php "); $foo = array_unique($foo);
will still contain 4 entries.
if entries contain spaces should trim
these.
Comments
Post a Comment