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);
Comments
Post a Comment