(2014-06-24, 08:00:53)shawn_a Wrote: sort_array_cat is a sorting comparison function, you need to use it with a sort function.
have you tried using subval_sort in core ?
Or you can try to use strcmp. If the first argument to strcmp is lexographically smaller to the second, then the value returned will be negative. If both are equal, then it will return 0.And if the first is lexograpically greater than the second then a positive number will be returned. Or use strcasecmp() which ignores case.
your sorting function
PHP Code:
function sort_cat($a, $b)
{
$a = $a['category'];
$b = $b['category'];
return strcasecmp($a, $b);
}
then try follows
PHP Code:
$manager = new ImController();
$preferences = imModel::getPref();
$output_arr = array();
foreach($preferences->categories->category as $cat)
{
ImCategory::setCategory($cat);
$manager->runModelMethod('gen_register');
$items = array_reverse($manager->getModelValue('items_ordered_struct'));
$strcat = (string) $cat;
$output_arr[] = array( 'category' => $strcat,
'value' => '<a class=" my_class" title="' . $strcat . '"
href="nasza-oferta?kategoria=' . $strcat . '">' . $strcat . ' (' . count($items) . ')</a><br />'
);
}
// There function call
usort($output_arr, 'sort_cat');
foreach($output_arr as $output)
{
echo $output['value'];
}