How can the PHP max() function be correctly used to find the maximum value of a column in a MySQL query result?

When using the PHP max() function to find the maximum value of a column in a MySQL query result, you need to iterate through the result set and extract the values of the specific column. You can store these values in an array and then use the max() function to find the maximum value from that array.

// Assume $result is the MySQL query result
$values = [];
while ($row = $result->fetch_assoc()) {
    $values[] = $row['column_name']; // Replace 'column_name' with the actual column name
}

$max_value = max($values);
echo "The maximum value is: " . $max_value;