How do I remove duplicates from an array?
Let's say that my I have two arrays named $array
and $new_array
. $array
has contents while $new_array
is empty, as seen below:
$array = array(5,1,2,1,5,7,10);
$new_array = array();
I want $new_array
to store the unique values of $array
. It kind of goes like this:
$array = array(5,1,2,1,5,7,10);
$new_array = array(5,1,2,7,10); // removing the 1 and 5 after 2 since those numbers are already a duplicate of the preceding numbers.
echo $new_array; // Output: 512710