• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/util/collection.php
  • Класс: BitrixTasksUtilCollection
  • Вызов: Collection::sort
public function sort($conditions = array())
{
	if(empty($conditions))
	{
		return $this;
	}

	$fields = array_keys($conditions);
	$field = $fields[0];
	$way = ToLower($conditions[0]) == 'desc' ? 0 : 1;

	$cb = function($a, $b) use ($field, $way) {

		$aVal = $a[$field];
		$bVal = $b[$field];

		if($aVal == $bVal)
		{
			return 0;
		}

		if($way > 0)
		{
			return ($aVal < $bVal) ? -1 : 1;
		}
		else
		{
			return ($aVal < $bVal) ? 1 : -1;
		}
	};

	uasort($this->values, $cb);

	// we may implement option that will preserve keys, but for now just reset them
	$this->values = array_values($this->values);

	return $this;
}