diff --git a/modules/contact.module b/modules/contact.module
index da34b83e00de42e16b9db2285d63f793c40e82b0..076d284b0ec3582af5e2b13cf9157237847995ab 100644
--- a/modules/contact.module
+++ b/modules/contact.module
@@ -463,8 +463,9 @@ function contact_mail_page() {
       }
       else {
         // If there is only one category, store its cid.
+        $category_keys = array_keys($categories);
         $form['cid'] = array('#type' => 'value',
-          '#value' => array_shift(array_keys($categories)),
+          '#value' => array_shift($category_keys),
         );
       }
       $form['message'] = array('#type' => 'textarea',
diff --git a/modules/contact/contact.module b/modules/contact/contact.module
index da34b83e00de42e16b9db2285d63f793c40e82b0..076d284b0ec3582af5e2b13cf9157237847995ab 100644
--- a/modules/contact/contact.module
+++ b/modules/contact/contact.module
@@ -463,8 +463,9 @@ function contact_mail_page() {
       }
       else {
         // If there is only one category, store its cid.
+        $category_keys = array_keys($categories);
         $form['cid'] = array('#type' => 'value',
-          '#value' => array_shift(array_keys($categories)),
+          '#value' => array_shift($category_keys),
         );
       }
       $form['message'] = array('#type' => 'textarea',