How to join the arrays in ascending order with array unique

1

Well it's the following I have the following code:

$cars = array("Volvo", "BMW", "Toyota", "BMW", "Ferrari");
$cars2 = array_unique($cars);

echo $cars2[0];
echo "<br><br>";
echo $cars2[1];
echo "<br><br>";
echo $cars2[2];
echo "<br><br>";
echo $cars2[3];

When I show $cars2[3], it shows me an error, but in theory I wanted it to show me the Ferrari, that is how I can do to join the arrays , excluding the repeated ones, and that the arrays have always worked.

How can I do this?

    
asked by anonymous 23.12.2016 / 23:25

1 answer

2
$cars  = array("Volvo", "BMW", "Toyota", "BMW", "Ferrari");
$cars2 = array_unique($cars);
$cars2 = array_values($cars2);

print_r($cars2);
    
23.12.2016 / 23:30