本文整理汇总了PHP中TYPO3\CMS\Core\Utility\ArrayUtility::sortArraysByKey方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayUtility::sortArraysByKey方法的具体用法?PHP ArrayUtility::sortArraysByKey怎么用?PHP ArrayUtility::sortArraysByKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\CMS\Core\Utility\ArrayUtility
的用法示例。
在下文中一共展示了ArrayUtility::sortArraysByKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRecordsSortedByTitle
/**
* Returns an array of all non-deleted records of a table sorted by a given title field.
* The value of the title field will be replaced by the return value
* of self::getRecordTitle() before the sorting is performed.
*
* @param array $fields Fields to select
* @param string $table Table name
* @param string $titleField Field that will contain the record title
* @param string $where Additional where clause
* @return array Array of sorted records
*/
protected static function getRecordsSortedByTitle(array $fields, $table, $titleField, $where = '')
{
$fieldsIndex = array_flip($fields);
// Make sure the titleField is amongst the fields when getting sorted
$fieldsIndex[$titleField] = 1;
$result = array();
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $table, '1=1 ' . $where . self::deleteClause($table));
while ($record = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
// store the uid, because it might be unset if it's not among the requested $fields
$recordId = $record['uid'];
$record[$titleField] = self::getRecordTitle($table, $record);
// include only the requested fields in the result
$result[$recordId] = array_intersect_key($record, $fieldsIndex);
}
$GLOBALS['TYPO3_DB']->sql_free_result($res);
// sort records by $sortField. This is not done in the query because the title might have been overwritten by
// self::getRecordTitle();
return \TYPO3\CMS\Core\Utility\ArrayUtility::sortArraysByKey($result, $titleField);
}
示例2: sortArraysByKeyThrowsExceptionForNonExistingKey
/**
* @test
* @expectedException \RuntimeException
*/
public function sortArraysByKeyThrowsExceptionForNonExistingKey()
{
ArrayUtility::sortArraysByKey(array(array('a'), array('a')), 'dummy');
}