I tried many ways, I have an array:
array(1) { [0]=> string(113) "23138,19031,22951,22951,22962,18858,18858,18858,18858,18858,18858,18858,18858,18858,18858,18858,18858,18858,18858" }
Tried:
$a = array_map("unserialize", array_unique(array_map("serialize", $a)));
var_dump($a);
Or
$a = array_unique($a);
var_dump($a);
And
$a = array_values(array_unique($a));
var_dump($a);
Nothing, I still get duplicated values, the full code would be:
$user_id = get_current_user_id();
$postid = $post->ID;
$userPosts= get_user_meta( $user_id, 'save_post', TRUE );
$userPosts = str_replace(' ', '', $userPosts);
$a = explode(', ', $userPosts);
$a = array_values(array_unique($a));
var_dump($a);
update_user_meta( $user_id, 'save_post', $a );
$array = array_unique( explode("," $string) );$userPosts = str_replace(' ', '', $userPosts); $a = explode(', ', $userPosts);you remove spaces then you try to explode with comma space but there are no spaces, you just removed them, so the output should be one item. One long string that you try to remove duplicates from. This should be cought if you had done proper debugging