Array ( [0] => 158 [1] => 171 [2] => 172 ) 2Duplicate Duplicate Duplicate Array ( [0] => 172 ) 0Duplicate Array ( [0] => 171 [1] => 172 [2] => 173 [3] => 174 ) 3Duplicate Duplicate Duplicate Duplicate Array ( [0] => 172 [1] => 173 ) 1Duplicate Duplicate Array ( ) -1 Array ( ) -1 Array ( [0] => 160 [1] => 172 ) 1Duplicate Duplicate Array ( ) -1 Array ( [0] => 168 [1] => 170 [2] => 172 ) 2Duplicate Duplicate Duplicate Array ( [0] => 168 [1] => 172 ) 1Duplicate Duplicate Array ( [0] => 158 [1] => 171 [2] => 172 ) 2Duplicate Duplicate Duplicate Array ( ) -1 Array ( [0] => 171 ) 0Duplicate Array ( ) -1 Array ( [0] => 171 ) 0Duplicate Array ( [0] => 171 ) 0Duplicate Array ( ) -1 Array ( [0] => 171 ) 0Duplicate Array ( [0] => 168 [1] => 171 ) 1Duplicate Duplicate Array ( [0] => 169 [1] => 171 ) 1Duplicate Duplicate Array ( ) -1 Array ( [0] => 168 [1] => 170 [2] => 172 ) 2Duplicate Duplicate Duplicate Array ( [0] => 168 ) 0Duplicate Array ( [0] => 168 ) 0Duplicate Array ( ) -1 Array ( ) -1 Array ( ) -1 Array ( [0] => 168 ) 0Duplicate Array ( [0] => 168 ) 0Duplicate Array ( [0] => 168 ) 0Duplicate Array ( [0] => 158 ) 0Duplicate Array ( [0] => 158 ) 0Duplicate Array ( [0] => 158 ) 0Duplicate Array ( [0] => 158 ) 0Duplicate Array ( [0] => 158 ) 0Duplicate Array ( [0] => 158 ) 0Duplicate Array ( [0] => 158 ) 0Duplicate Array ( [0] => 160 [1] => 161 ) 1Duplicate Duplicate Array ( [0] => 158 [1] => 160 [2] => 161 ) 2Duplicate Duplicate Duplicate Array ( [0] => 158 ) 0Duplicate I have a array and i want to remove duplicate entry from this array....supp 158 comes so many times........i want only one 158 not all .I have to do this for all duplicate values .....Please help me .........I am so confused to do this....
I'm confused too. Do you have one array or do you have many arrays? If you want to remove duplicates from a single array, you can use array_unique: http://php.net/manual/en/function.array-unique.php
$sql=mysql_query("select id,title,description from f_topics where tid='$loginid'"); while($row=mysql_fetch_array($sql)) { $data=$row['description']; $extract=word($data); $data1=implode(',',array_keys($extract)); $break=explode(",",$data1); foreach($break as $value) { $sqlk=mysql_query("select id,title from f_topics where title LIKE '%$value%' or description LIKE '%$value%' GROUP BY id "); $myarray=array(); while($row1=mysql_fetch_assoc($sqlk)) { $val=array_unique($row1); $myarray[]=$val['id']; } $unique_array = array_unique($myarray); //echo '<pre>', print_r($unique_array, true), '</pre>'; Firstly thanks for reply.......... this is my code actually i have created a code that automatically extract keyword from description and match this keyword in all other description if it found it display the result .now my problem is thst suppose i have two keyword data and water.my code search for data in all description and display result ...then it search for water if it found in same description it display result twice... i use distinct but it didn't work.....the above code give the result..... Array ( [0] => 158 [1] => 171 [2] => 172 ) Array ( [0] => 172 ) Array ( [0] => 171 [1] => 172 [2] => 173 [3] => 174 ) Array ( [0] => 172 [1] => 173 ) Array ( ) Array ( ) Array ( [0] => 160 [1] => 172 ) Array ( ) Array ( [0] => 168 [1] => 170 [2] => 172 ) Array ( [0] => 168 [1] => 172 ) Array ( [0] => 158 [1] => 171 [2] => 172 ) Array ( ) Array ( [0] => 171 ) Array ( ) Array ( [0] => 171 ) Array ( [0] => 171 ) Array ( ) Array ( [0] => 171 ) Array ( [0] => 168 [1] => 171 ) Array ( [0] => 169 [1] => 171 ) Array ( ) Array ( [0] => 168 [1] => 170 [2] => 172 ) Array ( [0] => 168 ) Array ( [0] => 168 ) Array ( ) Array ( ) Array ( ) Array ( [0] => 168 ) Array ( [0] => 168 ) Array ( [0] => 168 ) Array ( [0] => 158 ) Array ( [0] => 158 ) Array ( [0] => 158 ) Array ( [0] => 158 ) Array ( [0] => 158 ) Array ( [0] => 158 ) Array ( [0] => 158 ) Array ( [0] => 160 [1] => 161 ) Array ( [0] => 158 [1] => 160 [2] => 161 ) Array ( [0] => 158 ) now what i want that for ex 158 appears in so many array......so i want only one 158 when i am reading this array...all duplicate id are deleted or removed.......Please help me in solving this..............
Could you merge the all the arrays into one using array_merge and then call array_unique? Otherwise, you could maintain an array of every number that's been used already. Then use array_diff between this array and your arrays. $used=array(); foreach($break as $value) { $sqlk=mysql_query("select id,title from f_topics where title LIKE '%$value%' or description LIKE '%$value%' GROUP BY id "); $myarray=array(); while($row1=mysql_fetch_assoc($sqlk)) { $myarray[]=$val['id']; } $myarray = array_unique($myarray); $myarray = array_diff($myarray, $used); $used = array_merge($used, $myarray); } PHP: