need help to sort elements


#1

I have a function like this:
PHP Code:
public static function getAllUrls()
{
$db = JFactory::getDBO();

    $db->setQuery(" 
        SELECT * FROM #__mk_search_items              
        WHERE state = 1"); 
         
    $urls = $db->loadAssocList(); 
     
    $data = []; 
     
    foreach($urls as $url) 
    { 
        $data[] = ['label' => $url['name'], 'name' => $url['url'], 'target' => $url['target']];         
    } 
     
    return $data; 
}  

I need to sort the elements picked from the SELECT statement in alphabetically order before it is all put into the $data element.

I need help to do this, please.


#2

You just need to add an ORDER BY to your query.

ORDER BY column_name ASC

#3

Thanks a lot, it works!