How can I remove duplicate values from an array in PHP? -


array=[{"abc":"qwe","sdsd":"ewewe","fff":"gggg"},  {"poi":"ytr","wert":"yui","iuyy":"yes"},  {"abc":"qwe","sdsd":"ewewe","fff":"gggg"},  {"poi":"ytr","wert":"yui","iuyy":"yes"},  {"abc":"qwe","sdsd":"ewewe","fff":"gggg"},  {"poi":"ytr","wert":"yui","iuyy":"yes"},  {"abc":"qwe","sdsd":"ewewe","fff":"gggg"}] 

the output be:

array=[{"abc":"qwe","sdsd":"ewewe","fff":"gggg"},  {"poi":"ytr","wert":"yui","iuyy":"yes"}] 

please me solve question if trying

this code

    <?php      $array=[{"abc":"qwe","sdsd":"ewewe","fff":"gggg"},      {"poi":"ytr","wert":"yui","iuyy":"yes"},      {"abc":"qwe","sdsd":"ewewe","fff":"gggg"},      {"poi":"ytr","wert":"yui","iuyy":"yes"},      {"abc":"qwe","sdsd":"ewewe","fff":"gggg"},      {"poi":"ytr","wert":"yui","iuyy":"yes"},      {"abc":"qwe","sdsd":"ewewe","fff":"gggg"}];      $array = array_unique($array);      echo $array;      ?> 

then getting run time error; while initializing please getting data big existing function.

try this..

array_unique() sorts values treated string @ first, keep first key encountered every value, , ignore following keys. not mean key of first related value unsorted array kept.

$getarray=json_decode(yourarray,true);  $array=array_unique($getarray); 

http://php.net/manual/en/function.array-unique.php


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -