當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。