let me break it down:
$sql = 'SELECT MAX(thread_id) AS max_thread_id FROM threads';
this creates a variable for an SQL query that gets the highest value in the "thread_id" column using the MAX() aggregate function and stores it in a varibale called "max_thread_id".
$result = mysql_query ($sql);
...runs the query and stores the result set as $result
$array = mysql_fetch_assoc ($result);
...spools the result set into an associative array
extract ($array);
...extracts out the array element as a global variable so now you have a variable $max_thread_id that is the last thread_id that was inserted. All of the above code can be done in a single line:
extract (mysql_fetch_assoc (mysql_query ("SELECT MAX(thread_id) AS max_thread_id FROM threads")));
then add 1 to that varibale:
$next_autoindex = $max_thread_id + 1;
$next_autoindex is the value of whatever the next insert auto_incerement will be.