Quantcast
Channel: DaniWeb Solved Topics
Viewing all articles
Browse latest Browse all 587

List Sort Function

$
0
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]);
    });
}

Viewing all articles
Browse latest Browse all 587

Trending Articles