need help to sort elements

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.

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

ORDER BY column_name ASC

Thanks a lot, it works!

Sponsor our Newsletter | Privacy Policy | Terms of Service