Callback function for sorting an array of objects on a key

@param   array  &$a  An array of objects
@param   array  &$b  An array of objects
@return   integer  Comparison status
@see     self::sortObjects()
320586
protected static function _sortObjects(&$a, &$b)
  {
    $key = self::$sortKey;

    for($i=0, $count=count($key); $i<$count; $i++){
      if ( isset(self::$sortDirection[$i]) ){
        $direction = self::$sortDirection[$i];
      }

      if ( isset(self::$sortCase[$i]) ){
        $caseSensitive = self::$sortCase[$i];
      }

      if ( isset(self::$sortLocale[$i]) ){
        $locale = self::$sortLocale[$i];
      }

      $va = $a->$key[$i];
      $vb = $b->$key[$i];

      if ( (is_bool($va) or is_numeric($va)) and (is_bool($vb) or is_numeric($vb)) ){
        $cmp = $va - $vb;
      }
      elseif ( $caseSensitive ){ 
        $cmp = strcmp($va, $vb, $locale);
      }
      else {
        $cmp = strcasecmp($va, $vb, $locale);
      }

      if ( $cmp > 0 ){

        return $direction;
      }

      if ( $cmp < 0 ){
        return -$direction;
      }
    }

    return 0;
  }
784660
protected function sortByScore(Identification $a, Identification $b)
    {
        if (is_null($this->scoreKey)) {
            throw new \BadMethodCallException('The key to sort on must be defined using SetScoreKey() prior to sorting.');
        }
        
        if ($a->getScore($this->scoreKey) == $b->getScore($this->scoreKey)) {
            return 0;
        }
        
        return $a->getScore($this->scoreKey) > $b->getScore($this->scoreKey) ? $this->returnTrue : $this->returnFalse;
    }
1202898
protected function compare(string $a, string $b): int
    {
        global $sortOrder;

        $aIndex = array_search($a, $sortOrder);
        $bIndex = array_search($b, $sortOrder);
        if ($aIndex === false) {
            return -1;
        }

        if ($bIndex === false) {
            return 1;
        }

        return $aIndex - $bIndex;
    }
93331
public function similarity(&$A, &$B)
    {
        // Make the arrays into sets
        $a = array_fill_keys($A,1);
        $b = array_fill_keys($B,1);

        // Count the cardinalities of the sets
        $a_count = count($a);
        $b_count = count($b);

        if ($a_count == 0 || $b_count == 0) {
            return 0;
        }

        // Compute the intersection and count its cardinality
        $intersect = count(array_intersect_key($a,$b));

        return $intersect/min($a_count,$b_count);
    }
229800
protected function sortItemsByPriority(
        PrioritizableInterface $a,
        PrioritizableInterface $b
    ) {
        $priorityA = $a->priority();
        $priorityB = $b->priority();

        if ($priorityA === $priorityB) {
            return 0;
        }

        return ($priorityA < $priorityB) ? (-1) : 1;
    }
216242
public static function asort(array &$array, int $sort_flags = SORT_REGULAR): void
    {
        self::decorateOriginalArray($array);
        uasort($array, function ($a, $b) use ($sort_flags) {
            if ($a[1] == $b[1])
                return $a[0] - $b[0];
            $arr = [
                - 1 => $a[1],
                1 => $b[1]
            ];
            asort($arr, $sort_flags);
            reset($arr);
            return key($arr);
        });
        self::undecorateSortedArray($array);
    }
1226106
private static function sortReports ($a, $b){
    	$a = json_decode($a, true);
    	$b = json_decode($b, true);
    	
    	if ($a['value']['optional'] == $b['value']['optional']){
    		return 0;
    	}
    	else{
    		return ($a['value']['optional'] < $b['value']['optional']) ? -1 : 1;
    	}
    }
542623
public static function sortObjectArrayByNumber( $array, $attribute, $asc = true ) {

		uasort( $array, function( $item1, $item2 ) use ( $attribute, $asc ) {

			if( $asc ) {

				return $item1->$attribute > $item2->$attribute;
			}
			else {

				return $item1->$attribute < $item2->$attribute;
			}
		});

		return $array;
	}
691444
protected function sortByScore($a, $b)
    {

        if ($a->score == $b->score) {
            return 0;
        }

        return ($a->score > $b->score) ? -1 : 1;

    }
898176
public static function sort(
        array $array,
        callable $callback,
        int $options = SORT_REGULAR,
        bool $descending = false
    ): array {
        $results = [];

        // First we will loop through the items and get the comparator from a callback
        // function which we were given. Then, we will sort the returned values and
        // and grab the corresponding values for the sorted keys from this array.
        foreach ($array as $key => $value) {
            $results[$key] = $callback($value, $key);
        }

        $descending ? arsort($results, $options) : asort($results, $options);

        // Once we have sorted all of the keys in the array, we will loop through them
        // and grab the corresponding model so we can set the underlying items list
        // to the sorted version. Then we'll just return the collection instance.
        foreach (array_keys($results) as $key) {
            $results[$key] = $array[$key];
        }

        return $results;
    }
1010635
protected function sortByRank(Identification $a, Identification $b)
    {
        if ($a->getRank() == $b->getRank()) {
            return 0;
        }
        
        return $a->getRank() > $b->getRank() ? $this->returnTrue : $this->returnFalse;
    }
230082
protected static function uksortMatchFunc($a, $b)
	{
		$posa = array_search($a, self::$uksortMatchList);
		$posb = array_search($b, self::$uksortMatchList);
		if ($posa == $posb) {
			return 0;
		} else {
			return $posa > $posb ? 1 : -1;
		}
	}
1296053
public function sortQueue($a, $b)
    {
        $buildTimeA = $a->getNextBuildTime();
        $buildTimeB = $b->getNextBuildTime();

        if ($buildTimeA == $buildTimeB) {
            return 0;
        }

        return $buildTimeA < $buildTimeB ? -1 : 1;
    }
289618
protected function comparePluginPriorities($a, $b)
    {
        if ($this->pluginStorage[$a]['priority'] === $this->pluginStorage[$b]['priority']) {
            return 0;
        }

        return ($this->pluginStorage[$a]['priority'] > $this->pluginStorage[$b]['priority']) ? -1 : 1;
    }
252541
public static function sortByKey($_array, $key) {
        $array = $_array;
        $result = usort($array, function($a, $b) use ($key) {
            return strcmp(call_user_func(array($a, $key)),
                          call_user_func(array($b, $key)));
        });
        if (!$result)
            throw new ArrayException("sorting by \"$key\" failed");
        return $array;
    }
746290
protected static function sortFileList(array $a, array $b)
  {
    if(!array_key_exists("src", $a) || !array_key_exists("src", $b))
    {
      return 0;

      throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
    }

    return strcmp(strtolower($a["src"]), strtolower($b["src"]));
  }
131758
protected function sortItems($a, $b)
    {
        $aSortVal = 0; //a sort value for a comparison check for the value of $a
        $bSortVal = 0; //a sort value for a comparison check for the value of $b

        if ($this->sortBy == 'date') {
            $aSortVal = strtotime($a->getConversationMessageDateTime());
            $bSortVal = strtotime($b->getConversationMessageDateTime());
        } elseif ($this->sortBy == 'rating') {
            $aSortVal = $a->getConversationMessagetotalRatingScore();
            $bSortVal = $b->getConversationMessagetotalRatingScore();
        }

        if ($this->sortByDirection == 'asc') {
            if ($aSortVal > $bSortVal) {
                return 1;
            } elseif ($aSortVal < $bSortVal) {
                return -1;
            } else {
                return 0;
            }
        } else {
            if ($aSortVal > $bSortVal) {
                return -1;
            } elseif ($aSortVal < $bSortVal) {
                return 1;
            } else {
                return 0;
            }
        }
    }