当前位置: 首页>>代码示例>>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;未经允许,请勿转载。