What are some common pitfalls when working with arrays in PHP, especially when handling unique values and sorting?

One common pitfall when working with arrays in PHP is not properly handling unique values. If you want to ensure that an array only contains unique values, you can use the array_unique() function. Another pitfall is incorrectly sorting arrays. To sort an array in ascending order, you can use the sort() function.

// Handling unique values in an array
$originalArray = [1, 2, 3, 2, 4, 5, 3];
$uniqueArray = array_unique($originalArray);
print_r($uniqueArray);

// Sorting an array in ascending order
$numbers = [5, 3, 8, 1, 2];
sort($numbers);
print_r($numbers);