0

I have a function that I need help with. The purpose of the function is to sort an array of objects by field. This function was using the PHP function create_function which is now deprecated in PHP 7.2. I've been trying to rewrite the function, but the results return null. Any help in figuring out what's wrong is greatly appreciated.

function _list_sort(&$objects, $on, $order = 'ASC')
{
    usort($objects, function(&$a,&$b) use($on, $order) {
        return ($order === 'DESC') ? strcmp($a[$on],$b[$on]) : strcmp($a[$on],$b[$on]);
    });
}
1
Contributor
0
Replies
10
Views
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.