Warning: uasort(): Array was modified by the user comparison function in FacetapiWidget->applySorts() I'm trying to build my own sorting function implementing hook_facetapi_sort() and sorting the following data by weight.

name, weight
dog, -2
cat, 1
zebra, -5
dolphin, 3
bee, 5


The code I wrote so far is the following one.

function zoo_facetapi_sort_animal(array $a, array$b) {
  $a = db_query("select weight from {animal} where name = :a", array(':a' =&gt; $a['#markup']))-&gt;fetchAssoc();
  $b = db_query("select weight from {animal} where name = :b", array(':b' =&gt; $b['#markup']))-&gt;fetchAssoc();

  $a_value = (isset($a['weight'])) ? $a['weight'] : 0;
  $b_value = (isset($b['weight'])) ? $b['weight'] : 0;

  return strnatcmp($b_value, $a_value);
}


The result is what I expected.

zebra
dog
cat
dolphin
bee


I get the following error message. 


  Warning: uasort(): Array was modified by the user comparison function in FacetapiWidget->applySorts() (line 230 of /var/www/zoo.dev/sites/all/modules/facetapi/plugins/facetapi/widget.inc)


How do I avoid getting that message?
Register your own function as FacetAPI sort callback. Then select it in the FacetAPI sort order.

http://example.com/admin/config/search/facetapi/search_api%40default_node_index/block/field_animal_type/edit

http://drupalcontrib.org/api/drupal/contributions%21facetapi%21facetapi.api.php/function/hook_facetapi_sort_info/7

NB: You also accidentally collapsed the space between array and $b

function zoo_facetapi_sort_animal(array $a, array$b) {...}

/**
 * Implements hook_facetapi_sort_info
 */  
function zoo_facetapi_sort_info() {
  $sorts = array();

  $sorts['active'] = array(
    'label' =&gt; t('Animal ...'), 
    'callback' =&gt; 'zoo_facetapi_sort_animal', 
    'description' =&gt; t('Sort by whether the animal is ...'), 
    'weight' =&gt; -50,
  );

  return $sorts;
}


function zoo_facetapi_sort_animal(array $a, array $b) {
  ...
}