Store the labels as an array, then loop through the array, adding the selected=selected to the printed line if conditon is true for the comparison of the $_POST['subject'] value and the array element. Check to see if there is a value in the $_POST['subject'] before the comparison loop, or by using an isset(), and handle accordingly.