I am trying to get the maximum value in field "id".

What is really happening is that "$id" is actually taking the lowest value of the "$rowid" array.

How do I get the highest value in "$rowid"?

PHP Code:
    $sql "SELECT `id` FROM `table1`";
    
$result mysql_query($sql$conn);
    
$rowid mysql_fetch_array($resultMYSQL_ASSOC);
    if (
$rowid != "") {
        
$id  max($rowid);
    } 
P.S. You can not take the "max" of a null array.