What are the potential pitfalls of using max() function in PHP to find the highest value in an array?

The potential pitfall of using the max() function in PHP to find the highest value in an array is that it will return the highest value based on their string representation, not their actual numeric value. This can lead to unexpected results when comparing numbers as strings. To solve this issue, you can use a custom comparison function with the usort() function to properly compare the numeric values in the array.

// Custom comparison function to compare numeric values
function compareNumbers($a, $b) {
    return $a - $b;
}

// Array of numbers
$numbers = [10, 5, 20, 15];

// Sort the array in ascending order using custom comparison function
usort($numbers, "compareNumbers");

// Get the highest value from the sorted array
$highestValue = end($numbers);

echo $highestValue; // Output: 20