即使我使用array_unique函數,我也無法「從數組中刪除」double值!從數組中刪除重複的值
<?php
$tags_array = array() ;
$query_tags = $mysql->Query("SELECT words AS kw FROM users ") ;
/****
*
* This query return something like 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']) as $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 like this Array([1] => Asp [2] => Php [3] => Php [4] => Ruby [5] => Jquery [6] => Php [7] => Asp_net [8] = >C# [9] => Asp)
*
* IT'S ONLY AN EXAMPLE TO SHOW YOU THE SITUATION
*****/
?>
嘗試'trim'值。 –
對不起,我是小菜鳥告訴我誰能做到這一點:(道歉我 – Claudio
也許有一些空白介入?例如,''PHP,Ruby「,」Asp,PHP「 - > array(」PHP「,」Ruby 「,」Asp「,」PHP「)' –