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


PHP SplFixedArray類代碼示例

本文整理匯總了PHP中SplFixedArray的典型用法代碼示例。如果您正苦於以下問題:PHP SplFixedArray類的具體用法?PHP SplFixedArray怎麽用?PHP SplFixedArray使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: bytestring

 public function bytestring($data)
 {
     $a = new \SplFixedArray(strlen($data));
     for ($i = 0; $i < strlen($data); $i++) {
         $a[$i] = str_pad(ord($data[$i]), 3, ' ', STR_PAD_LEFT);
     }
     return implode(' ', $a->toArray());
 }
開發者ID:chuyskywalker,項目名稱:phpaes,代碼行數:8,代碼來源:Util.php

示例2: values

 /**
  * Returns a Collection of the values.
  *
  * @return Collection
  */
 public function values()
 {
     $count = $this->count()->toNative();
     $valuesArray = new \SplFixedArray($count);
     foreach ($this->items as $key => $item) {
         $valuesArray->offsetSet($key, $item->getValue());
     }
     return new Collection($valuesArray);
 }
開發者ID:embarknow,項目名稱:value-objects,代碼行數:14,代碼來源:Dictionary.php

示例3: sort

 /**
  * {@inheritdoc}
  */
 public function sort(\SplFixedArray $array)
 {
     $length = $array->count();
     for ($i = 1; $i < $length; $i++) {
         $key = $array[$i];
         $j = $i - 1;
         while ($j >= 0 && $array[$j] > $key) {
             $array[$j + 1] = $array[$j];
             $j--;
         }
         $array[$j + 1] = $key;
     }
     return $array;
 }
開發者ID:valdislav,項目名稱:SplFixedArray,代碼行數:17,代碼來源:InsertionSortStrategy.php

示例4: testFromArrayDisordered

 public function testFromArrayDisordered()
 {
     $array = array(1 => 'foo', 3 => 'bar', 2 => 'baz', 0 => 'qux');
     $the_DS = DynamicArray::fromArray($array);
     $SPL_DS = \SplFixedArray::fromArray($array);
     $this->assertMethodsEqual($SPL_DS, $the_DS);
 }
開發者ID:daniel-ac-martin,項目名稱:php-seids,代碼行數:7,代碼來源:DynamicArrayTest.php

示例5: __construct

 /**
  * Create a new instance.
  *
  * @param array            $matchRegexps The regexes to match files.
  *
  * @param AbstractFilter[] $filters      The filters to apply.
  */
 public function __construct(array $matchRegexps, $filters)
 {
     foreach ($matchRegexps as $pattern) {
         $this->matchRegexps[] = $this->toRegex($pattern);
     }
     $this->filters = \SplFixedArray::fromArray($filters);
 }
開發者ID:cyberspectrum,項目名稱:pharpiler,代碼行數:14,代碼來源:Collection.php

示例6: sort

 /**
  * {@inheritdoc}
  */
 public function sort(\SplFixedArray $array)
 {
     $length = $array->count();
     for ($i = 0; $i < $length - 1; $i++) {
         $smallest = $i;
         for ($j = $i + 1; $j < $length; $j++) {
             if ($array[$j] < $array[$smallest]) {
                 $smallest = $j;
             }
         }
         $tmp = $array[$i];
         $array[$i] = $array[$smallest];
         $array[$smallest] = $tmp;
     }
     return $array;
 }
開發者ID:valdislav,項目名稱:SplFixedArray,代碼行數:19,代碼來源:SelectionSortStrategy.php

示例7: fromArray

 /**
  * @param array $array
  * @param boolean $save_indexes = true
  * @return SplFixedArray, DataStructures\SerializableFixedArray
  */
 public static function fromArray(array $array, $save_indexes = true)
 {
     if (self::$_useSpl === null) {
         self::_checkEnvironment();
     }
     return self::$_useSpl ? \SplFixedArray::fromArray($array, $save_indexes) : new self(count($array), $save_indexes ? $array : array_values($array));
 }
開發者ID:performics,項目名稱:ga-cli-api,代碼行數:12,代碼來源:SerializableFixedArray.class.php

示例8: testMapTraversable

 public function testMapTraversable()
 {
     $expected = [1, 2, 3, 4];
     $arr = \SplFixedArray::fromArray($expected);
     $actual = t::into([], t::map(t::value()), $arr);
     $this->assertEquals($expected, $actual);
 }
開發者ID:bahulneel,項目名稱:phonon,代碼行數:7,代碼來源:ReduceTest.php

示例9: copyOf

 /**
  * Create a new ImmutableVector from the given traversable.
  * @param array|Traversable $traversable
  * @param bool $preserveKeys
  * @return ImmutableVector
  */
 public static function copyOf($traversable, $preserveKeys = true)
 {
     if (is_array($traversable)) {
         return new self(\SplFixedArray::fromArray($traversable, $preserveKeys));
     } else {
         return new self(\SplFixedArray::fromArray(iterator_to_array($traversable), $preserveKeys));
     }
 }
開發者ID:hoesler,項目名稱:traver,代碼行數:14,代碼來源:ImmutableVector.php

示例10: slice

 /**
  * @param int|string $start
  * @param int|string $length
  * @return $this
  */
 public function slice($start, $length)
 {
     $end = $this->set->getSize();
     if ($start > $end || $length > $end) {
         throw new \RuntimeException('Invalid start or length');
     }
     $this->set = \SplFixedArray::fromArray(array_slice($this->set->toArray(), $start, $length));
     return $this;
 }
開發者ID:nmarley,項目名稱:bitcoin-php,代碼行數:14,代碼來源:WitnessCollectionMutator.php

示例11: valuesDataProvider

 public function valuesDataProvider()
 {
     $splFixedArrayIn = \SplFixedArray::fromArray([2, 154, 2342, 1001, 7651, 4523, 1343, 756, 6324, 1]);
     $expected = [1, 2, 154, 756, 1001, 1343, 2342, 4523, 6324, 7651];
     $splFixedArrayIn2 = clone $splFixedArrayIn;
     $splFixedArrayIn2[9] = 8000;
     $expected2 = [2, 154, 756, 1001, 1343, 2342, 4523, 6324, 7651, 8000];
     return [[$splFixedArrayIn, $expected], [$splFixedArrayIn2, $expected2]];
 }
開發者ID:valdislav,項目名稱:SplFixedArray,代碼行數:9,代碼來源:SortStrategyTest.php

示例12: fromArray

 /**
  * Imports a PHP array in a FixedArray instance.
  *
  * This method needs to be reimplemented as SplFixedArray does not return `new static`.
  * @see https://bugs.php.net/bug.php?id=55128
  *
  * Subclasses of FixedArray do not need to reimplement this method.
  *
  * @param array   $array
  * @param boolean $saveIndexes
  *
  * @return FixedArray
  *
  * @throws \InvalidArgumentException If the array contains non-numeric or negative indexes.
  */
 public static function fromArray($array, $saveIndexes = true)
 {
     $splFixedArray = \SplFixedArray::fromArray($array, $saveIndexes);
     $result = new static($splFixedArray->count());
     $source = $saveIndexes ? $array : $splFixedArray;
     foreach ($source as $key => $value) {
         $result[$key] = $value;
     }
     return $result;
 }
開發者ID:brick,項目名稱:brick,代碼行數:25,代碼來源:FixedArray.php

示例13: __construct

 /**
  * 
  * @param PointInterface[] $points
  * @param LineFactoryInterface $lineFactory
  */
 public function __construct(array $points, LineFactoryInterface $lineFactory)
 {
     $items = [];
     for ($i = 0; $i < count($points) - 1;) {
         $items[] = $lineFactory->createLineSegment($points[$i], $points[++$i]);
     }
     // and add last segment
     $items[] = $lineFactory->createLineSegment($points[$i], $points[0]);
     $this->items = \SplFixedArray::fromArray($items);
 }
開發者ID:samizdam,項目名稱:Geometry,代碼行數:15,代碼來源:LineSegmentCollection.php

示例14: getItem

 /**
  * {@inheritdoc}
  */
 public function getItem($index)
 {
     if (!$this->items->offsetExists($index)) {
         throw new \OutOfBoundsException('The index ' . $index . ' is not set');
     }
     return $this->items[$index];
 }
開發者ID:battlerattle,項目名稱:shuffle-bag,代碼行數:10,代碼來源:ArrayStorage.php

示例15: keep

 /**
  * @param int $numberOfCardsToKeep
  *
  * @return HandInterface
  */
 public function keep(int $numberOfCardsToKeep) : HandInterface
 {
     if ($this->cards->count() <= $numberOfCardsToKeep) {
         return $this;
     }
     return new self(...array_slice($this->getCards(), 0, $numberOfCardsToKeep));
 }
開發者ID:ranpafin,項目名稱:phpoker,代碼行數:12,代碼來源:Hand.php


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