Set option value in a select field
So here is the corrected code. I've changed some variable names to make it easier to understand.


$option and $pages became options
$page became $pages
$paged was retired


As @Sujith-Nara mentions you don't need array_unique as the keyed approach will make them unique by default. This does presume that the page titles are unique across the site (which is not enforced). You could replace the key with $p-&gt;nid or $p-name if the titles aren't unique.

Because the keys are now strings you can use ksort instead of sort to order them on the key.

$pages = $sql-&gt;execute();
$options = array();

// Populate page dropdown
foreach($pages as $p)
{
    $options[$p-&gt;title] = $p-&gt;title;
    // $options[$p-&gt;name] = $p-&gt;title;
    // $options[$p-&gt;nid] = $p-&gt;title;
}

// Sort the array alphabetically in ASC Order
ksort($paged);

$form['group_owner_filter']['select'] = array(
    '#type' =&gt; 'select',
    '#title' =&gt; t('Filter by Name'),
    '#default_value' =&gt; t('Make a selection...'),
    '#options' =&gt; $options
);