A
A
Ar jeck2017-06-19 17:02:57
PHP
Ar jeck, 2017-06-19 17:02:57

How to remove duplicate array values?

Good afternoon. Such a question:
Let's say there is an array Need to convert it to array_unique is not suitable, because
$array = [1, 5, 5, 9];
[1, 5, 9]

array_unique([1, 5, 5, 9]) == [[0] => 1, [1] => 5, [3] => 9]

and this is not at all what is needed.
I will explain right away why this is needed - this array is then turned into JSON and instead of the necessary one it turns out["1","5","9"]{"0":"1","1":"5","3":"9"}

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
R
Rsa97, 2017-06-19
@MrDenzzz

$unique = array_keys(array_flip($array));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question