當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Collection::map方法代碼示例

本文整理匯總了PHP中Cake\Collection\Collection::map方法的典型用法代碼示例。如果您正苦於以下問題:PHP Collection::map方法的具體用法?PHP Collection::map怎麽用?PHP Collection::map使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Cake\Collection\Collection的用法示例。


在下文中一共展示了Collection::map方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testCompile

 /**
  * Tests that by calling compile internal iteration operations are not done
  * more than once
  *
  * @return void
  */
 public function testCompile()
 {
     $items = ['a' => 1, 'b' => 2, 'c' => 3];
     $collection = new Collection($items);
     $callable = $this->getMock('stdClass', ['__invoke']);
     $callable->expects($this->at(0))->method('__invoke')->with(1, 'a')->will($this->returnValue(4));
     $callable->expects($this->at(1))->method('__invoke')->with(2, 'b')->will($this->returnValue(5));
     $callable->expects($this->at(2))->method('__invoke')->with(3, 'c')->will($this->returnValue(6));
     $compiled = $collection->map($callable)->compile();
     $this->assertEquals(['a' => 4, 'b' => 5, 'c' => 6], $compiled->toArray());
     $this->assertEquals(['a' => 4, 'b' => 5, 'c' => 6], $compiled->toArray());
 }
開發者ID:ripzappa0924,項目名稱:carte0.0.1,代碼行數:18,代碼來源:CollectionTest.php

示例2: override

 /**
  * Set an override for a column, columns or restore all to default
  * 
  * Pass CRUDDATA_DEFAULT_OVERRIDES (FALSE) to restore to default types for all columns
  * Pass string_name, string_value to override one column
  * Pass [
  *		string_name => string_value,
  * 		string_name => string_value
  * ] for multiple overrides at once
  * 
  * @param array|string|boolean $override
  * @param string $type
  * @return array
  */
 public function override($override = NULL, $type = 'string')
 {
     if ($override === CRUDDATA_DEFAULT_OVERRIDES) {
         $this->_clearOverrides();
     } elseif (is_string($override)) {
         $this->_columns[$override]['type'] = $type;
     } elseif (is_array($override)) {
         foreach ($override as $column => $type) {
             $this->_columns[$column]['type'] = $type;
         }
     }
     $columns = new Collection($this->columns());
     $overrides = [];
     return $columns->map(function ($value, $key) use(&$overrides) {
         return $overrides[$key] = ['type' => $value['type']];
     })->toArray();
 }
開發者ID:OrigamiStructures,項目名稱:CrudViews,代碼行數:31,代碼來源:CrudData.php


注:本文中的Cake\Collection\Collection::map方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。