What are the potential pitfalls of using nested loops to find the two highest values in an array in PHP?

Using nested loops to find the two highest values in an array can be inefficient and lead to poor performance, especially for large arrays. A better approach would be to sort the array in descending order and then retrieve the first two elements of the sorted array.

<?php
// Sample array
$array = [5, 3, 8, 2, 7, 1];

// Sort the array in descending order
rsort($array);

// Get the first two elements
$highest_values = array_slice($array, 0, 2);

// Output the two highest values
echo "The two highest values are: " . implode(", ", $highest_values);
?>