Ver originalforeach ($dataset as $key => $row){ $username[$key] = $row['username']; } if ($_GET['tsort']=='down') array_multisort($username, SORT_ASC,$dataset); else array_multisort($username, SORT_DESC,$dataset);