function arraySortByElements($array2sort,$sortField,$order,$iscount=false) {
$functionString='
if ('.($iscount?'true':'false').'){
if(count($a["'.$sortField.'"]) > count($b["'.$sortField.'"])) return 1*'.$order.';
if(count($a["'.$sortField.'"]) < count($b["'.$sortField.'"])) return -1*'.$order.';
}else{
if($a["'.$sortField.'"] > $b["'.$sortField.'"]) return 1*'.$order.';
if($a["'.$sortField.'"] < $b["'.$sortField.'"]) return -1*'.$order.';
}
return 0;';
usort($array2sort, create_function('$a,$b',$functionString));
return $array2sort;
}