Sort an array by the nested arrays it contains. Helper function for getMatchingBlocks.

@param array $a First array to compare.
@param array $b Second array to compare.

@return int -1, 0 or 1, as expected by the usort function.
337396
private function tupleSort($a, $b)
    {
        $aLength = count($a);
        $bLength = count($b);

        if ($aLength > $bLength) {
            $max = $aLength;
        } else {
            $max = $bLength;
        }

        for ($i = 0; $i < $max; ++$i) {
            if ($a[$i] < $b[$i]) {
                return -1;
            }

            if ($a[$i] > $b[$i]) {
                return 1;
            }
        }

        return $aLength <=> $bLength;
    }
948069
public function sort_by_many_fields($a, $b) {
        foreach ($this->sortfields as $field => $mult) {
            // Nulls first.
            if (is_null($a->$field) && !is_null($b->$field)) {
                return -$mult;
            }
            if (is_null($b->$field) && !is_null($a->$field)) {
                return $mult;
            }

            if (is_string($a->$field) || is_string($b->$field)) {
                // String fields.
                if ($cmp = strcoll($a->$field, $b->$field)) {
                    return $mult * $cmp;
                }
            } else {
                // Int fields.
                if ($a->$field > $b->$field) {
                    return $mult;
                }
                if ($a->$field < $b->$field) {
                    return -$mult;
                }
            }
        }
        return 0;
    }
558410
public function sortItems( eZPageBlockItem $a, eZPageBlockItem $b )
    {
        if ( $a->attribute('priority') == $b->attribute('priority') )
        {
            if ( $a->attribute('ts_publication') > $b->attribute('ts_publication') )
            {
                return 1;
            }
            else if ( $a->attribute('ts_publication') < $b->attribute('ts_publication') )
            {
                return -1;
            }
            else
            {
                return 0;
            }
        }
        else if ( $a->attribute('priority') > $b->attribute('priority') )
        {
            return -1;
        }
        else if ( $a->attribute('priority') < $b->attribute('priority') )
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
736487
protected function yearSort($a, $b)
    {
        $aDates = $this->extractNewestDates($a);
        $bDates = $this->extractNewestDates($b);

        if (count($aDates) > 0 && count($bDates) > 0) {
            return $bDates[0] - $aDates[0];
        } elseif (count($aDates) > 0 && count($bDates) === 0) {
            return -1;
        } elseif (count($aDates) === 0 && count($bDates) > 0) {
            return 1;
        } else {
            return 0;
        }
    }
113780
public function sortItemsByPriority( eZPageBlockItem $a, eZPageBlockItem $b )
    {
        if ( $a->attribute('priority') > $b->attribute('priority') )
        {
            return -1;
        }
        else if ( $a->attribute('priority') < $b->attribute('priority') )
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
391012
protected static function sortItems($a, $b)
    {
        $subpatha = substr($a, 11); // /dashboard
        $subpathb = substr($b, 11); // /dashboard
        $segmentsa = explode('/', $subpatha);
        $segmentsb = explode('/', $subpathb);
        $segmenta = substr($subpatha, 0, strpos($subpatha, '/'));
        $segmentb = substr($subpathb, 0, strpos($subpathb, '/'));
        if (count($segmentsa) == 3 && count($segmentsb) == 3) {
            $subpatha = $segmenta[0] . '/' . $segmenta[1];
            $subpathb = $segmentb[0] . '/' . $segmentb[1];
            $segmenta .= '/' . $segmentsa[1];
            $segmentb .= '/' . $segmentsb[1];
        }

        if (!$segmenta) {
            $segmenta = $subpatha;
        }
        if (!$segmentb) {
            $segmentb = $subpathb;
        }
        $db = Database::connection();
        $displayorderA = intval($db->GetOne('select cDisplayOrder from Pages p inner join PagePaths cp on p.cID = cp.cID where cPath = ?', ['/dashboard/' . $segmenta]));
        $displayorderB = intval($db->GetOne('select cDisplayOrder from Pages p inner join PagePaths cp on p.cID = cp.cID where cPath = ?', ['/dashboard/' . $segmentb]));

        if ($displayorderA > $displayorderB) {
            return 1;
        } elseif ($displayorderA < $displayorderB) {
            return -1;
        } else {
            $displayorderA = intval($db->GetOne('select cDisplayOrder from Pages p inner join PagePaths cp on p.cID = cp.cID where cPath = ?', ['/dashboard/' . $subpatha]));
            $displayorderB = intval($db->GetOne('select cDisplayOrder from Pages p inner join PagePaths cp on p.cID = cp.cID where cPath = ?', ['/dashboard/' . $subpathb]));
            if ($displayorderA > $displayorderB) {
                return 1;
            } elseif ($displayorderA < $displayorderB) {
                return -1;
            }
        }
    }
905919
protected static function arrayMerge($a, $b)
    {
        foreach ($b as $k => $v) {
            if (!is_array($v) || isset($a[$k]) && !is_array($a[$k])) {
                $a[$k] = $v;
            } else {
                $a[$k] = self::arrayMerge(isset($a[$k])? $a[$k]: array(), $v);
            }
        }
        return $a;
    }
1188471
public static function compare(Match $a, Match $b)
    {
        if ($a->quality !== $b->quality) {
            return $a->quality > $b->quality ? -1 : 1;
        }

        if ($a->index !== $b->index) {
            return $a->index > $b->index ? 1 : -1;
        }

        return 0;
    }
552267
public static function cloud_sort($a, $b) {
        $tagsort = self::$cloudsortfield ?: 'name';

        if (is_numeric($a->$tagsort)) {
            return ($a->$tagsort == $b->$tagsort) ? 0 : ($a->$tagsort > $b->$tagsort) ? 1 : -1;
        } else if (is_string($a->$tagsort)) {
            return strcmp($a->$tagsort, $b->$tagsort);
        } else {
            return 0;
        }
    }
839608
public static function compare($a, $b)
    {
        if ($a->getRow() == $b->getRow()) {
            return $a->getCell() - $b->getCell();
        }

        return $a->getRow() - $b->getRow();
    }
947426
public function sortReports($a, $b)
    {
        return $this->reportsProvider->compareCategories($a['category'], $a['subcategory'], $a['order'], $b['category'], $b['subcategory'], $b['order']);
    }
442373
protected function sortProperty($a, $b) {
    $property = $this->sortProperty;
    $parent = $this->sortParent;
    if (isset($parent)
        && (isset($a->$parent->$property) || isset($b->$parent->$property))) {
      if (!$this->sortCaseSensitive
          && is_string($a->$parent->$property)
          && is_string($b->$parent->$property)) {
        $aprop = strtoupper($a->$parent->$property);
        $bprop = strtoupper($b->$parent->$property);
        if ($aprop > $bprop) {
          return 1;
        }
        if ($aprop < $bprop) {
          return -1;
        }
      } else {
        if ($a->$parent->$property > $b->$parent->$property) {
          return 1;
        }
        if ($a->$parent->$property < $b->$parent->$property) {
          return -1;
        }
      }
    }
    // If they have the same parent, order them by their own property.
    if (!$this->sortCaseSensitive
        && is_string($a->$property)
        && is_string($b->$property)) {
      $aprop = strtoupper($a->$property);
      $bprop = strtoupper($b->$property);
      if ($aprop > $bprop) {
        return 1;
      }
      if ($aprop < $bprop) {
        return -1;
      }
    } else {
      if ($a->$property > $b->$property) {
        return 1;
      }
      if ($a->$property < $b->$property) {
        return -1;
      }
    }
    return 0;
  }
893651
public function compare($a, $b)
    {
        if ($this->collator instanceof \Collator) {
            return $this->collator->compare($a, $b);
        } else {
            return $a == $b ? 0 : ($a > $b ? 1 : -1);
        }
    }
545769
public static function sort(ServiceDeliveryInterface $a, ServiceDeliveryInterface $b)
    {
        if ($a->getPriority() === $b->getPriority()) {
            return 0;
        }

        return $a->getPriority() > $b->getPriority() ? -1 : 1;
    }
1240633
protected function compare($a, $b)
    {
        if (is_null($this->comparator)) {
            if ($a < $b) {
                return -1;
            }
            if ($a > $b) {
                return 1;
            }
            return 0;
        }

        return call_user_func($this->comparator, $a, $b);
    }
193697
private static function sortKeys($array, $order)
    {
        uksort($array, function ($a, $b) use ($order) {
            $pos_a = array_search($a, $order);
            $pos_b = array_search($b, $order);

            if ($pos_a === false)
                return 1;
            if ($pos_b === false)
                return -1;

            return $pos_a - $pos_b;
        });

        return $array;
    }
1175778
protected static function sortFileList(array $a, array $b)
  {
    if(!array_key_exists("src", $a) || !array_key_exists("src", $b) || !array_key_exists("type", $a) || !array_key_exists("type", $b))
    {
      return 0;

      throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
    }
    
    if($a["type"] != $b["type"])
    {
      return ($a["type"] < $b["type"]) ? -1 : 1;
    }

    return strcmp(strtolower($a["src"]), strtolower($b["src"]));
  }