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' => $a['#markup']))->fetchAssoc(); $b = db_query("select weight from {animal} where name = :b", array(':b' => $b['#markup']))->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?