With sorting the list it is easier for the user to locate items in a sorted list than unsorted. It rearranges the data in specific order (ascending or descending).
You can either use PHP or AJAX to get the sorted data.
I am using AJAX to sort the list in this tutorial.
In this tutorial, I am displaying the employee’s list and attach click event on the table column header. Whenever header gets clicked then send an AJAX request with column name to sort with.