当前位置: 首页>>代码示例>>PHP>>正文


PHP ArrayUtility::sortArraysByKey方法代码示例

本文整理汇总了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);
 }
开发者ID:samuweiss,项目名称:TYPO3-Site,代码行数:30,代码来源:BackendUtility.php

示例2: sortArraysByKeyThrowsExceptionForNonExistingKey

 /**
  * @test
  * @expectedException \RuntimeException
  */
 public function sortArraysByKeyThrowsExceptionForNonExistingKey()
 {
     ArrayUtility::sortArraysByKey(array(array('a'), array('a')), 'dummy');
 }
开发者ID:Mr-Robota,项目名称:TYPO3.CMS,代码行数:8,代码来源:ArrayUtilityTest.php


注:本文中的TYPO3\CMS\Core\Utility\ArrayUtility::sortArraysByKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。