A php usort function I never used.

/**
* value_compare_func
* The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be
* respectively less than, equal to, or greater than the second.
**/
$my_sort_function = function($a, $b)
{
$result = 0;

if( $a->featured == ‘yes’ && $b->featured ==’no’ )
{
$result = 1; // a > b == 1
}
else if ( $a->featured == ‘no’ && $b->featured == ‘yes’ )
{
$result = -1; // a < b == -1
}
else if( $a->featured == $b->featured )
{
// now check the pexpires_unixtimestamp
if( $a->pexpires_unixtimestamp > $b->pexpires_unixtimestamp )
{
$result = 1;
}
else if( $b->pexpires_unixtimestamp > $a->pexpires_unixtimestamp )
{
$result = -1;
}
else
{
$result = 0;
}
}

return $result;
};

// usort function I never used.

 

Leave a Reply

Your email address will not be published. Required fields are marked *